Select all columns after JOIN in LINQ

后端 未结 1 1211
感情败类
感情败类 2020-12-01 17:14

I have two tables, Table1 and Table2. I want to perform, say, a left outer join:

var myOutput = from object1 in Table1
                     


        
相关标签:
1条回答
  • 2020-12-01 17:33

    You have to specify each manually if you want to project into a flattened type. Your other option is to just have your combined type contain both objects, and the objects will naturally bring along their properties.

    select new 
    {
        Object1 = object1,
        Object2 = output
    };
    

    And you would work with it like myObj.Object1.Property1, myObj.Object2.Property4, etc.

    One final option that still involves some manual work is to define an appropriate type and have a constructor or a builder method that does the work of segmenting out your object properties into a flattened type. You still perform the manual mapping, but you isolate it from your query logic.

    select new CombinedType(object1, output);
    //or 
    select builder.GetCombinedType(object1, output);
    
    0 讨论(0)
提交回复
热议问题