开发者

How to do a "join" in a LINQ query against the Entity Framework

开发者 https://www.devze.com 2022-12-19 08:26 出处:网络
I have the following table structure which has been imported into the Entity Framework.I need to write a LINQ query where I select the ent开发者_C百科ities of Table1, where a field in Table2 is equal

I have the following table structure which has been imported into the Entity Framework. I need to write a LINQ query where I select the ent开发者_C百科ities of Table1, where a field in Table2 is equal to true, and a field in Table 3 is equal to a specific GUID.

Could someone help with this?

Thanks you.

alt text http://digitalsamurai.us/images/drawing2.jpg


Try:

from t3 in dataContext.Table3
  where t3.Guidfield == someGuid
  from t2 in t3.Table2
  where t2.Field // boolean field is true
  select t2.Table1;

EDIT: As requested, equivalent lambda expression syntax:

dataContext.Table3.Where(t3 => t3.Guidfield == someGuid)
              .SelectMany(t3 => t3.Table2)
              .Where(t2 => t2.Field)
              .Select(t2.Table1);


from t1 in table1
join t2 in table2
on t1.table1PK equals t2.table1PK
join t4 in table4
on t2.table2PK equals t4.table2PK
join t3 in table3
on t3.table3PK equals t4.table3PK
where  t2.randomBoolColumn == true && t3.GUID == myGUIDVariable
select t1;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号