Convert SQL to LINQ to Entities WHERE IN clause

后端 未结 2 1917
无人及你
无人及你 2021-01-29 03:38

How can I convert this sql statetment to LINQ to Entities?

SQL Statement:

Select * from Departments where DepartmentID  in (Select DepartmentID from Empl         


        
相关标签:
2条回答
  • 2021-01-29 04:10
    (from d in db.Departments
     join e in db.Employees
         on d.DepartmentID equals e.DepartmentID
     where e.FirstName.Contains("FirstName") ||
           e.LastName.Contains("LastName")
     select t).Distinct()
    
    0 讨论(0)
  • 2021-01-29 04:16

    u could use this

    var x = 
        (from t0 in db.Employees
        where
          t0.FirstName.Contains("FirstName") ||
          t0.LastName.Contains("LastName")
        select new {
          t0.DepartmentID
        }).FirstOrDefault().DepartmentID;
    
    from t in db.Departments
    where
      t.DepartmentID.contains(x.DepartmentID)
    select t
    
    0 讨论(0)
提交回复
热议问题