如何在linq中使用左连接

时间:2017-08-11 04:44:25

标签: sql linq

我正在尝试使用linq编写左连接但它会出错。这是sql代码:

        Select  
          Case s.StudentID
          When 1000 Then s.Amount
          End As Amount
        From    Student s
        Left Join Course cOn c.Time = s.ForDate And c.StudentID= s.ID And s.Amount= 1000

这是我尝试过的代码,但是它给左连接错误了:

       from s in Student
         join c in Course
                                          on new {s.ForDate , s.ID}
                                          equals new { c.Time, c.StudentID}                                     
                                          into inj

                                            from i in inj.DefaultIfEmpty()
                                            where s.Amount= 1000

1 个答案:

答案 0 :(得分:0)

试试这个

from s in Student
         join c in Course  on new {A=s.ForDate ,B= s.ID}
                           equals new {A= c.Time,B= c.StudentID}                                     
                           into inj
                           from i in inj.DefaultIfEmpty()
                           where s.Amount == 1000
                           select new{
                           ///
                           }