Monday, February 07, 2011

“IN” clause in LINQ

"IN" Clause in LINQ
Some time we have a requirement to select records with more than one criteria as same as "IN" clause with SQL like:
"Where EmpId IN (1,2,3)"
We can do this with LINQ to Object also, we have to use "Contains" function like below
public static Employee[] GetEmployee(string[] EmpID)
{
        return (from p in GetEmp()
        where EmpID.Contains(p.EmployeeID)
        select p).ToArray<Employee>();
}

No comments: