Compiled queries and “Parameters cannot be sequences”

倾然丶 夕夏残阳落幕 提交于 2019-12-08 17:34:21

问题


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);         
}

回答1:


This article has your answer:

Queries with list parameters cannot be precompiled because the translation of the query is dependent on the number of items in the list.



来源:https://stackoverflow.com/questions/813256/compiled-queries-and-parameters-cannot-be-sequences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!