2010-05-19 29 views
1

我使用下面的方法:LINQ和载有()

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 does not recognize the method 'Boolean Contains(mrhome.Models.ConsaltCost)' method, and this method cannot be translated into a store expression. 

我怎样才能解决呢?

回答

2

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

以下网址显示了支持的查询操作http://msdn.microsoft.com/en-us/library/bb738550.aspx