c# - Join Extension Method -
i having trouble figuring out how simple left join using linq in extension method.
i need use extension method opposed comprehension query paging results.
var carparkpagedlist = db.carpark .join(db.userprofiles, cp => cp.userprofileid, => up.userid, (cp, up)) .orderby(f => f.name) .where(f => f.floorid == floorid) .select(f => new carparklistdisplaymodel { carparkid = f.carparkid, name = f.name }).topagedlist(page, 10);
i cannot find on anywhere, have tried 101 linq examples , find comprehension queries won't provide support extension methods.
ok simon, approach worked , use on, more logical.
var carparkpagedlist = (from cp in db.carpark cp.floorid == floorid join occupant in db.userprofiles on cp.userprofileid equals occupant.userid gj occupant in gj.defaultifempty() orderby cp.name select new carparklistdisplaymodel { carparkid = cp.carparkid, name = cp.name, usersname = (occupant == null ? "un-ocupied" : occupant.firstname + " " + occupant.lastname) }).topagedlist(page, 10);
Comments
Post a Comment