LINQ to Entities不识别方法'Boolean Contains(Int32)'方法 [英] LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method

查看:703
本文介绍了LINQ to Entities不识别方法'Boolean Contains(Int32)'方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的异常流程


LINQ to Entities不会识别方法'Boolean
Contains(Int32)'方法,并且该方法不能被翻译成
到一个存储表达式。

LINQ to Entities does not recognize the method 'Boolean Contains(Int32)' method, and this method cannot be translated into a store expression.

同时尝试执行以下查询

List<int> studentIDs = Common.getFilterStudents();
var query = from a in studentTable
            where studentIDs.Contains(a.StudentID)
            select a;

如何使用studentID列表过滤查询?

How can I filter the query using the studentIDs list?

推荐答案

不可以使用在您的EF版本中包含,因为支持包含在EF 4中添加了。可以升级EF版本(然后您的代码将无任何问题),或使用类似手动表达式构建

It is not possible to use Contains in your EF version, because support for Contains was added in EF 4. Either upgrade your EF version (then your code will work without any problems), or use something like manual expression building:

var query = context.studentTable.Where(
    BuildContainsExpression<Student, int>(s => s.StudentID, studentIDs));

这篇关于LINQ to Entities不识别方法'Boolean Contains(Int32)'方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆