加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

linq-to-sql – 编译的查询和“参数不能是序列”

发布时间:2020-12-12 07:09:12 所属栏目:MsSql教程 来源:网络整理
导读:我认为编译的查询将执行与DataContext相同的查询转换.但是当我尝试使用带有.Contains方法调用的查询时,我遇到了运行时错误.我哪里出错了? //private member which holds a compiled query.FuncDataAccess.DataClasses1DataContext,Listint,ListDataAccess.Te
我认为编译的查询将执行与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<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);         
}

解决方法

This article有你的答案:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读