Compiled queries and "Parameters cannot be sequences"

I thought that compiled queries would perform the same query translation as the DataContext. However, I get a runtime error when I try to use a request with a call to the .Contains method. Where am I wrong?

//private member which holds a compiled query. Func<DataAccess.DataClasses1DataContext, List<int>, List<DataAccess.TestRecord>> compiledFiftyRecordQuery = System.Data.Linq.CompiledQuery.Compile <DataAccess.DataClasses1DataContext, List<int>, List<DataAccess.TestRecord>> ((dc, ids) => dc.TestRecords.Where(tr => ids.Contains(tr.ID)).ToList()); //this method calls the compiled query. public void FiftyRecordCompiledQueryByID() { List<int> IDs = GetRandomInts(50); //System.NotSupportedException //{"Parameters cannot be sequences."} List<DataAccess.TestRecord> results = compiledFiftyRecordQuery (myContext, IDs); } 
+7
contains linq-to-sql
source share
1 answer

This article has your answer:

Queries with list parameters cannot be precompiled, because the translation query depends on the number of elements in the list.

+11
source share

All Articles