开发者

use in/join into lambda expression in Entity FrameWork

Hi there i have one sql query as below.

select * 
from Customers as C 
where
c.CompanyID in (
  select CompanyID 
  from Projects 
  where Projects.ID in (
    select ProjectAssignment开发者_C百科.ProjectID 
    from ProjectAssignment 
    where ProjectAssignment.EmployeeID = 7 
  ) or Projects.ID in (
    select T.ProjectID
    from Tasks as T 
    where t.AssignedUserID = 7
  )
)

How can i write it with lambda expression?


Try that (not sure it working):

var projectIds1=ProjectAssignment.Where(pa=>pa.EmployeeID ==7).Select(ps=>pa.ProjectID);

var projectIds2=Tasks.Where(t=>t.AssignedUserID ==7).Select(t=>t.ProjectID);

var companyIds=Projects.Where(p=>projectIds1.Contains(p.ID) || projectIds2.Contains(p.ID)).
    Select(p=>p.CompanyID);

var result=Customers.Where(c=>companyIds.Contains(c.CompanyID));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜