所以我有这个查询:
var list = (from x in xList
join a in AList on x.commonfield equals a.commonfield
join b in BList on x.newCommonField equals b.newCommonField
from c in Clist.Where(p=>p.connectorID==x.connectorID).DefaultifEmpty()
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,c.name}).ToList();
list.ForEach(el =>
{
el.x.DesiredFieldFromA= el.DesiredFieldFromA;
el.x.DesiredFieldFromB= el.DesiredFieldFromB ;
el.x.Name=el.name;
});
return list.Select(p=>p.x);
当我做 :
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,c.name}).ToList();
问题#1:我怎么能告诉它它仍然应该向我显示记录......但是如果 name 字段为空,则放置 string.empty。
一些东西:
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,c.name??string.Empty}).ToList();
问题#2:我怎么能告诉它即使“connectorID”为空..我仍然需要它来显示 x 记录
提前谢谢!
#1 和 #2 的解决方案如下:
from c in Clist.Where(p=>p.connectorID==x.connectorID).DefaultifEmpty()
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,name= (c==null) ?"Not Defined": c.name}).ToList();