Compiled Queries and "Parameters cannot be sequences"
Posted
by David B
on Stack Overflow
See other posts from Stack Overflow
or by David B
Published on 2009-05-01T20:59:05Z
Indexed on
2010/05/03
7:08 UTC
Read the original article
Hit count: 338
I thought that compiled queries would perform the same query translation as DataContext. Yet I'm getting a run-time error when I try to use a query with a .Contains method call. Where have I gone 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);
}
© Stack Overflow or respective owner