How to make a “connection” in a LINQ query with Entity Framework

I have the following table structure that has been imported into the Entity Framework. I need to write a LINQ query where I select the entities of table 1, where the field in table 2 is true and the field in table 3 is equal to a specific GUID.

Can anyone help with this?

Thank.

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

+3
source share
2 answers

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, the equivalent syntax of the lambda expression is:

dataContext.Table3.Where(t3 => t3.Guidfield == someGuid)
              .SelectMany(t3 => t3.Table2)
              .Where(t2 => t2.Field)
              .Select(t2.Table1);
+5
source
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
source

Source: https://habr.com/ru/post/1731934/