views:

44

answers:

3

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

+1  A: 

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));
Justin Niessner
+1  A: 
var result=(from e in DataContext.Employee
           where CompanyListIds.Contains(e.CompanyId)).ToList();
Albin Sunnanbo
+1  A: 

Try this:

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