2

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.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?

1 Answer 1

1

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.