c# - linq multi left join to same property -
is possible write linq query? (in .net 3.5)
select tt.id ,tt.detailscount ,ttdmx.detailorder ,ttdmx.detailtype ,ttdm1.detailorder ,ttdm1.detailtype ,ttdm2.detailorder ,ttdm2.detailtype test.testtable tt left join test.testtabledetails ttdmx on tt.id = ttdmx.causeid , tt.maxcausedetailorder = ttdmx.detailorder left join test.testtabledetails ttdm1 on tt.id = ttdm1.causeid , tt.maxcausedetailorder - 1 = ttdm1.detailorder left join test.testtabledetails ttdm2 on tt.id = ttdm2.causeid , tt.maxcausedetailorder - 2 = ttdm2.detailorder
the classes this:
public class test { public int id {get;set;} public ilist<testdetails> details {get;set} }
and
public class testdetails { public int id {get;set;} public int detailorder {get;set;} public int detailtype {get;set;} }
i tried queryover can't join same property twice.
the easiest way write:
... ttdmx in db.testtabledetails.where(x => tt.id == x.causeid && tt.maxcausedetailorder == x.detailorder).defaultifempty() ...
this translated sql left join
Comments
Post a Comment