我在名为 Invoice 的类中有这个方法:
public static Expression<Func<Invoice, bool>> IsAllocated()
{
return i => i.TotalAmountDue == i.GetAllocationsTotal();
}
我有一个这样的列表:
IQueryable<Invoice> invoices
我需要像这样过滤它(它是 Linq to Entity):
var filteredInvoices = invoices.Where(i => Invoice.IsAllocated());
在这一行中我遇到了两个错误:
Cannot resolve method ... candidates are .... one in Enumerable and the other on in Queryable.
还有:
Cannot convert expression type
Expression<Func<Invoice,bool>>
to return type 'bool'
我已经尝试了很多我在 SO 中发现的东西,但都没有成功。有人可以告诉我这里缺少什么,或者至少,这两个错误中的哪一个是问题的根源?
最佳答案
您的方法已经返回了适当的表达式树 - 您只需要调用它,而不是在 lambda 表达式中调用它:
var filteredInvoices = invoices.Where(Invoice.IsAllocated());
关于c# - 无法解析 Enumerable 和 Queryable 候选人之间的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29856378/