【发布时间】:2015-03-12 08:16:48
【问题描述】:
我有表格请求,有批准:
public class Request {
public virtual List<Approval> Approvals { get; set; }
}
请求来自数据库
public DbSet<Request> Request { get; set; }
我有扩展方法:
public static IQueryable<Request> HaveApprovals(this IQueryable<Request> requests) {
return requests.Where(r => r.ActiveApprovals().Count() > 0).ToList();
}
还有另一种扩展方法:
public static IEnumerable<Approval> ActiveApprovals(this Request request) {
return request.Approvals.Where(a => !a.Deleted);
}
但出现错误:
LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[Domain.Approval] ActiveApprovals(Domain.Request)' method, and this method cannot be translated into a store expression.
由于某种原因,一种扩展方法能够被转换为 LINQ,但是当在另一种方法中使用扩展方法时,它无法转换。有什么建议吗?
【问题讨论】:
-
你也应该从第二个返回 IQueryable
-
如果可以的话我会,但
request.Approvals是List,使用Where 返回IEnumerable。
标签: c# linq entity-framework linq-to-entities extension-methods