Q:

Access data from indirect child table using LInq

I have following table in my database and im accessing them through EF.
TestPack { id, name, type }
Sheets{ id, tp_id, date, rev }
Spool { id, sheet_id, date, rev, fabricated, installed }

which means a test pack has 1-M sheets and each sheet has 1-M spools. I want to get count of total Spools in the Test Pack, and count of spools that are fabricated, count of spools that are installed. 
How do I get that through Linq query?

A:

if I understand you right,you would like to have something like this
 (from tp in ctx.TestPack
        join st in ctx.Sheets on st.tp_id equals tp.id
        join sl in ctx.Spool on sl.steet_id equals st.id
        where tp.id == testPackId //you can change or delete this condition
        select new {
          Total = sl.Count() , 
          FabricatedSpools = sl.Count(x=>x.fabricated == true),
          InstalledSpools = sl.Count(x=>x.installed == true)
     }).FisrtOrDefault();

Or maybe 
 (from tp in ctx.TestPack
    join st in ctx.Sheets on st.tp_id equals tp.id
    join sl in ctx.Spool on sl.steet_id equals st.id
    where tp.id == testPackId //you can change or delete this condition
    select new {
      Total = sl.Count() , 
      FabricatedSpools = (from s in sl
        where s.fabricated == true    
        select s.Count()),
      InstalledSpools = (from i in sl
        where i.installed== true    
        select i.Count()),
 }).FisrtOrDefault();

