开发者

Left join, return all columns from first table

开发者 https://www.devze.com 2023-02-23 00:35 出处:网络
Right now, for LEFT JOIN I use \"Include\": var items = (from item in Content.Entity1.Include(\"Entity2\")

Right now, for LEFT JOIN I use "Include":

var items = (from item in Content.Entity1.Include("Entity2")
            select new { Value1 = item.Col1, Value2 = item.Col1, ...., Value3 = item.TheReference.Col1});

There is a problem with that when there are many colum开发者_StackOverflow中文版ns in first entity that I have to type in.

Is there a possibility to return ALL columns from first entity and specific column for second entity?


Just return the left entity as a separate one and add additional ones that you wish:

from item in Content.Entity1.Include("Entity2")
select new { Left = item, Right = item.TheReference.Col1 };

Using T4

If your code is generic and is repeated entity-by-entity, then I suppose you could write a T4 template that would generate those LINQs for you. But that would mean that those custom right entity columns should be provided somehow via template variable.

So. Create a ttinclude file and then N tt files where you set additional variable values and reference the ttinclude generator template.

But other than these two (and yours with manual column write) there's nothing else really.

0

精彩评论

暂无评论...
验证码 换一张
取 消