Convert SQL to LINQ to Entities WHERE IN clause

后端 未结 2 1918
无人及你
无人及你 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: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
    

提交回复
热议问题