views:

153

answers:

2

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 entities 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

+4  A: 

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);
Håvard S
How would that translate to dot notation?
Sako73
Edited post to provide lambda expression syntax example.
Håvard S
Great answer. THank you.
Sako73
A: 
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;
Paul Creasey