So I have this Query:
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);
when I do :
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,c.name}).ToList();
Question#1: How can I tell it that it should still show me the record … but put string.empty if the name field is null.
Something along :
select new { x, a.DesiredFieldFromA, b.DesiredFieldFromB,c.name??string.Empty}).ToList();
Question#2: How can i tell it that even if “connectorID” is null .. i still need it to show the x record
Thanks in advance!
Solution for #1 and #2 was as follows :
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();
For Question #1, try this:
You need to specify the name “name” so you can use your expression to assign it.
For question #2, refer to jonnyGold’s answer.