Monday, 15 February 2010

c# - Linq: Include a join on the allready joined tables -



c# - Linq: Include a join on the allready joined tables -

i wondering if possible in linq: have 3 tables:

request --id --adress --description nav.properties: -- requeststatus requeststatus --requestid --pubdate --statustypeid nav.properties: -- request -- statustype statustype --id --statustypedescription nav.properties -- requeststatus

in linq, can manage first 2 table joined this:

var requestwithstatus = dbcontext.requests.include("requeststatus").tolist<fullrequest>();

but...what have statustypedescription column included in query (so utilize bring together on 3rd table).

if request instance can have 1 requeststatus, , requeststatus instance can have 1 statustype, do

var requestlist = dbcontext.requests.include("requeststatus.statustype").tolist();

there's "lambda" (expression>) overload include (in system.data.entity) (not sure work mysql)

var requestlist = dbcontext.requests.include(m => m.requeststatus.statustype).tolist();

all info nowadays in list (eager loading).

then can access description

var firstrequest = requestlist.first(); var requestdescription = firstrequest.description; var statustypedescription = firstrequest.requeststatus.statustype.description;

or safer

var statustypedescription = firstrequest.requeststatus != null && firstrequest.requeststatus.statustype != null ? firstrequest.requeststatus.statustype.description : string.empty;

c# mysql linq

No comments:

Post a Comment