c# - LINQ left outer join on date not working -


i have collection of groupedresult

iqueryable<groupedresult> groupedresult = p in db.departure group p new { p.terminal, p.departuredate, p.departuredate.month } g select new groupedresult {   terminal = g.key.terminal.code,   date = g.key.departuredate,   distance = g.count(),   month = g.key.month }; 

the problem collection has dates missing. example db.departure contains feb. 1, 2, 4, , 6. wanted show groupedresult feb. 3 , 5 use following code create collection of dates starting particular start date:

var dates = new list<datetime>();  (var dt = date; dt <= datetime.now; dt = dt.adddays(1)) {     dates.add(dt); } 

and join dates groupedresult

var result = p in groupedresult.tolist() q in dates.where(r => r == p.date).defaultifempty() select p; 

the result same 1 groupedresult. how can show entries no date data?

this because selecting p @ end.....you have create new anonymous class

var result = q in dates join p in groupedresult.tolist() on q equals p.date joinedresult r in joinedresult.defaultifempty() select new { terminal = r==null?null:r.terminal,   date = q,   distance = r==null?null:r.distance,   month = r==null?null:r.month }; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -