I'm attempting to write a CompiledQuery using Linq-to-Entities that will replace a stored procedure that takes two array (in this case, comma-delimited TEXT) parameters. Essentially, the SQL is be something like this:
*Stored Proc definition*
@ArrayParm1 TEXT,
@ArrayParm2 TEXT
-- etc.
SELECT [fieldList]
FROM someTable
WHERE someTable.Field1 IN (SELECT * FROM dbo.fncCSVToTable(@ArrayParm1))
AND someTable.Field2 IN (SELECT * FROM dbo.fncCSVToTable(@ArrayParm2))
dbo.fncCSVToTable
creates a single-column temp table with the array values.
Converting this to a compiled Linq-to-Entities query didn't seem difficult:
public static Func<EntityContext, List<int>, List<string> IQueryable<EntityType>>
SomeQuery =
CompiledQuery.Compile((EntityContext context, List<int> arrayParm1,
List<string> arrayParm2) =>
from c in context.SomeTableEntities
where arrayParm1.Contains(c.Field1)
&& arrayParm2.Contains(c.Field2)
select new EntityType
{
//projection
});
However, I get a runtime error stating that the parameters of Func<>
cannot be a List, and that only scalar parameters are supported. This makes sense to me, but I still feel like there's got to be a way to do this in a compiled query. Does anyone know of any way to do List.Contains
or WHERE ... IN
type functionality in a L2E CompiledQuery?