0

I have basically to select all employee from companies which are being passed so a variable -

CompanyListIds - Contains list of all company ids..

var result=DataContext.Employee(e=>e.CompanyId==companyId).ToList();

The above is a query I have for selecting from one company, now how would I modify it to compare with all the companyids that would be passed..how would I use contains maybe here..Thanks..

3 Answers 3

1
var result=(from e in DataContext.Employee
           where CompanyListIds.Contains(e.CompanyId)).ToList();
Sign up to request clarification or add additional context in comments.

Comments

1

If you have proper keys set up in the database and the navigation properties configured in your Entity Diagram, you should be able to do:

var result = DataContext.Companies.SelectMany(c => c.Employees);

But if not, you can simply use Contains:

var result = DataContext.Employee
                        .Where(e => CompanyListIds.Contains(e.CompanyId));

Comments

1

Try this:

var result= DataContext.Employee.Where(e=> CompanyListIds.Contains(e.CompanyId)).ToList();

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.