【发布时间】:2013-09-23 19:38:20
【问题描述】:
我想写如下代码 -
public IQueryable<Invoice> InvoiceFilterForMonthAndYear(DateTime? monthAndYear = null)
{
var invoices = _invoices.Where(MonthAndYearPredicate(monthAndYear);
return invoices;
}
private bool MonthAndYearPredicate(Invoice invoice, DateTime? monthAndYear)
{
//code to check if the invoice start or end dates is from the falls in the month I am checking for
}
但我不能使用这样的谓词,因为谓词只需要一个参数。
我知道我可以在 InvoiceFilterForMonthAndYear 中写一个 Where 子句来完成这项工作,但是
我想把比较的逻辑放到它自己的方法中。
【问题讨论】:
-
i => MonthAndYearPredicate(i, monthAndYear) -
@user1 这将编译,但查询提供程序将无法处理。
-
啊,全是 LTE。错过了标签。
标签: c# linq entity-framework linq-to-entities predicate