0

Hi I'm new to LINQ and got a requirement to convert below SQL into LINQ. Can someone help me how to write it?

select emp.id, emp.name from employee emp
left join department dept on dept.id = emp.deptid 
and (emp.managerid = '001' or (emp.manager in (select managerid from manager where location Contains('l001','l002','l003') and state =1)))

Thanks

1
  • what would this query expected to do? Commented Sep 5, 2013 at 11:33

1 Answer 1

1

Maybe something like this:

var locationIds = new List<string> {"l001", "l002", "l003"};
var ls=(
    from emp in db.employee
    from dept in db.department
        .Where(a=>a.id == emp.deptid).DefaultIfEmpty()
    where (emp.managerid == "001" 
        || db.manager.Where(w=>locationIds.Contains(w.location) && w.state == 1)
                     .Select(s=>s.managerid).Contains(emp.manager))
    select new
        {
            emp.id, 
            emp.name
        }
).ToList();

Where db is the linq data context

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Thanks for the response. Just I've small change in the query. instead of comparing with one string, I want to use contains. How can I do this? I've updated my post.
Update the answer. Have a look

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.