entity framework 4 - Flatten data in linq -


i have linq query need groupings select highest test date within month based on testtypeid, testtakerid, subareaid, subjectname, testdate.value.month, testdate.value.year.

the problem having nested lists concerned. there way flatten data group testtakerid, testtypeid, subareaid, subjectname, testdate.value.month, testdate.value.year.

the non-nested values(testtakerid, test.value.month, etc) work fine, nested(subareaid) values having trouble.

        var q1 = entry in result                  let testdate = entry.result.testdate                  testdate != null                  group entry new { entry.testtakerid, entry.testinstance.select(                 sr => sr.subject.select(c => c.subarea.id)), entry.testinstance.select(                 sr => sr.subject.select(c => c.subarea.name)),entry.testinstance.select(                 sr => sr.testinstance.test.testtype.id), testdate.value.month,                     testdate.value.year } g                  select g.where(entry => entry.result.testdate == g.max(e => e.result.testdate)); 

you must flatten result set first joining contained collections (testinstance , subject) , grouping:

var q1 = entry in result         ti in entry.testinstance  // translates sql join         su in ti.subject          // translates sql join         let testdate = entry.result.testdate         testdate != null         group entry new          {             entry.testtakerid,             su.subarea.id,             su.subarea.name,             ti.test.testtype.id,             testdate.value.month,              testdate.value.year         }          g         select g.where(entry => entry.result.testdate ==                                      g.max(e => e.result.testdate)); 

in fluent (or method) syntax statement from ti in entry.testinstance equivalent selectmany.


Comments