我有表请求,具有批准:
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,但是当在另一种扩展方法中使用扩展方法时,它将无法转换。有什么建议吗?
尝试通过这种方式重写您的HaveApprovals扩展名:
返回一个Iqueryable或Ienumerable而不是列表。该查询将由sql处理,因此它无法理解返回的列表