2017-09-14 80 views
0

我尽量让使用LINQ左查询:LEFT JOIN与LINQ用的EntityFramework

public IQueryable<Mutatie> GetMutaties() 
     { 
      var query = (from m in context.Mutatie 
         join d in context.tblDienstverband on m.fkDienstVerbandID equals d.DienstverbandID 
         join med in context.tblMedewerker on d.fkMedewerkerID equals med.MedewerkerID 
         where med.fkKlantID == this.klantId 
         select m).Include(d => d.fkDienstVerbandID); 
      return query; 
     } 

但如何让这有一个留网址查询?

谢谢

我有现在这样的:

var query = (from m in context.Mutatie 
         join d in context.tblDienstverband on m.fkDienstVerbandID equals d.DienstverbandID into grp 
         from d in grp.DefaultIfEmpty() 

         join med in context.tblMedewerker on d.fkMedewerkerID equals med.MedewerkerID into grp1 
         from med in grp.DefaultIfEmpty() 

         where med.fkMedewerkerID == this.klantId 
         select new { m, d, med }); 
      return query; 
+0

@请将w关于错误的更多细节CS0266 – hiule

回答

1

应该是这样的:

注:d和MED为空,如果没有行匹配

public IQueryable<Mutatie> GetMutaties() 
{ 
    var query = (from m in context.Mutatie 
       join d in context.tblDienstverband on m.fkDienstVerbandID equals d.DienstverbandID into grp 
       from d in grp.DefaultIfEmpty() 

       join med in context.tblMedewerker on d.fkMedewerkerID equals med.MedewerkerID into grp_med 
       from med in grp_med.DefaultIfEmpty() 

       where med.fkKlantID == this.klantId 
       //select new { m, d, med }; 
       select m; 
    return query; 
} 
+0

谢谢。但仍然有一些错误。 grp已经被转贴 –

+0

@Nielsfischerein我更新了答案。我们来试试吧 – hiule

+0

谢谢。我编辑帖子 –