Click here to Skip to main content
16,013,489 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i am new for linq and don't know much and need your help. i have following scenario:

employee table contains
EmpId as primary key
deptId as foreign key
Name
address

i have an anonymous object var deptlist in which i contain list of deptId. Now i want to select all employee from employee table that has any of the deptId as i have in my object deptlist.
Posted
Updated 29-May-10 2:16am
v2

1 solution

This is a fairly simple example that does what say that you need

C#
// Create a 'dummy' deptList as I don't know what yours contains
int[] ids = {1, 4, 5, 9};
var deptList = ids.Select(n => n);
var result = from e in Employees
where (deptList.Contains(e.deptid)
// I am only selecting Lastname, obviously you should select whichever fields you want.
select (e.LastName);


I have tested this against the Northwind database sample using e.EmployeeID instead of e.DeptID but that should make no difference to the outcome.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900