Linq和Contains()

Linq和Contains(),linq,contains,c#,lambda,Linq,Contains,C#,Lambda,我使用以下方法: public PageOfList<ConsaltQuestion> Filter(int? type, int pageId, EntityCollection<ConsaltCost> ConsaltRoles) { // return _dataContext.ConsaltQuestion.Where((o => o.Type == type || type == null) && (o=>o.P

我使用以下方法:

public PageOfList<ConsaltQuestion> Filter(int? type, int pageId, EntityCollection<ConsaltCost> ConsaltRoles)
    {
       // return _dataContext.ConsaltQuestion.Where((o => o.Type == type || type == null) && (o=>o.Paid == paid));
        return (from i in _dataContext.ConsaltQuestion where ((i.Type == type || type == null) && (i.Paid == true) && (ConsaltRoles.Contains(ConsaltCostDetails(i.Type.Value)))) select i).ToList().ToPageOfList(pageId, 20);
    }

如何修复它?

Linq to Entities不支持Contains方法。在这种情况下,您必须考虑使用内存中的对象(LINQ to Objts)使用包含过滤器逻辑。如果由于性能原因这不是一个可行的选项,我建议您创建一个执行contains的存储过程,然后将其映射到您的实体模型


以下url显示支持的查询运算符

Linq to Entities不支持Contains方法。在这种情况下,您必须考虑使用内存中的对象(LINQ to Objts)使用包含过滤器逻辑。如果由于性能原因这不是一个可行的选项,我建议您创建一个执行contains的存储过程,然后将其映射到您的实体模型


以下url显示了实体框架版本1不支持的受支持的查询运算符。版本4可以,但如果升级不可行,您可以通过建立表达式树来复制它


这里有一篇很好的文章,其中包含一些示例代码:

Entity Framework的版本1不支持Contains。版本4可以,但如果升级不可行,您可以通过建立表达式树来复制它

这里有一篇很好的文章,其中包含一些示例代码:

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