【问题标题】:Compiled queries and "Parameters cannot be sequences"编译查询和“参数不能是序列”
【发布时间】:2010-10-23 05:33:33
【问题描述】:

我认为编译后的查询会执行与 DataContext 相同的查询翻译。然而,当我尝试使用带有 .Contains 方法调用的查询时,我遇到了运行时错误。我哪里出错了?

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

【问题讨论】:

    标签: linq-to-sql contains linq.compiledquery


    【解决方案1】:

    This article有你的答案:

    带有列表参数的查询不能 预编译,因为翻译 查询取决于数字 列表中的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      相关资源
      最近更新 更多