2010-05-19 32 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