var query = from t1 in Context.Table1
join t2 in Context.Table2 on t1.Id equals t2.Id
join t3 in Context.Table3 on t3.Id equals t1.Id
join t4 in Context.Table4 on t1.Id equals t4.Id into temp
from temp_values in temp.DefaultIfEmpty()
where t1.Id == id
select new
{
Field1 = t1.Id,
Field2 = t1.Field2,
SpecialField = t4.temp_values
};
由于最后一次与Table4联接,我有此Linq查询返回2行。
请注意,两行在Field1和Field2上具有相同的值。
有什么聪明的方法可以只返回1行,将SpecialField标记为List,其中包含所有temp_values存储吗?
所以而不是:
Field1 / Field2/ SpecialField
1 /2 /{ Id=1, Prop1=2, Prop1=3}
1 /2 /{ Id=2, Prop1=12, Prop1=13}
我想要:
Field1 / Field2/ SpecialField
1 /2 /List with 2 entries: { Id=1, Prop1=2, Prop1=3}, { Id=2, Prop1=12, Prop1=13}