entity framework - Selective Linq child include two levels deep -


i'm porting sql stored procedure logic, return multiple tables in dataset, entity framework typed objects, queried linq.

basically need data tables a, b, , c, c has foreign key b, , b has foreign key a. don't want every c fk b, c's constraint x.

so basically, stored proc said

tablea = select a.aid = aidpassedin tableb = select b b.aid = aidpassedin tablec = select tableb tableb.xid = xidpassedin  return new dataset(tablea, tableb, tablec); //yes gross , confusing, our current efforts 

entity framework almost makes super easy so

a.include("b.c").where(a => a.aid == aidpassedin) 

my problem doesn't include constraint x on c table. i've read bunch of articles, i've read suggests things add clause, , filter objects end with. should end 1 object though, regardless of properties of it's children. want aidpassedin, , it's child b's, , b's children c match constraint x.

i feel 1 of worst phrased questions ever i'm @ bit of block. great thanks!

you can try along lines of following:

var alist = context.as.where(a => a.aid == aidpassedin)     .select(a => new     {         = a,         bs = a.bs,         cs = a.bs.select(b => b.cs.where(c => c.xid == xidpassedin))     })     .asenumerable()     .select(x => x.a)     .tolist(); // or singleordefault if aidpassedin pk 

entity framework put object graph automatically (even without using include) long don't disable change tracking.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -