I'm in the process of speeding up Linq to SQL queries in a web app by converting them to Compiled queries and I ran into a problem converting a very simple statement.
I want to compile a simple statement that uses the following parameters to get valid employees from the database:
TestParams myParams = new TestParams
{
ValidEmps = new int[] { 1, 2, 3 }
};
Here is the working query:
IQueryable<Employees> MySelectedEmps =
from emps in db.Employees
where myParams.ValidEmps.Contains(emps.EmployeeID)
select emps;
Here is my attempt at compiling it:
private static Func<MyDataContext, TestParams, IQueryable<Employee>> myCompiledQuery =
CompiledQuery.Compile((MyDataContext db, TestParams myParams) =>
from emps in db.Employees
where myParams.ValidEmps.Contains(emps.EmployeeID)
select emps);
This statement with compile and build, but when I run it, I receive the following run time error:
Comparison operators not supported for type 'System.Int32[]'
I have also tried passing a List and an IEnumerable with the same error message.
I have also tried replacing the .Contains statement with a .Any(valemp => valemp == emps.EmployeeID) statement but I still get the same error.
Is it possible to have a compiled query that uses the equivalent of the SQL "IN" statement? What am I doing wrong?