Tuesday, June 13, 2017

Left join with condition linQ

Left join with condition linQ
 from p in context.Periods  
 join f in context.Facts on p.id equals f.periodid into fg  
 from fgi in fg.Where(f => f.otherid == 17).DefaultIfEmpty()  
 where p.companyid == 100  
 select f.value  
 Or you could use a subquery:  
 from p in context.Periods  
 join f in context.Facts on p.id equals f.periodid into fg  
 from fgi in (from f in fg  
        where f.otherid == 17  
        select f).DefaultIfEmpty()  
 where p.companyid == 100  
 select f.value  

No comments:
Write comments