我有一个问题需要我数周才能解决,但我一直没能解决。
我有一堂课,我有两种方法。以下应该从数据库中获取最新日期。该日期代表客户对“某事”所做的最新付款:
public DateTime getLatestPaymentDate(int? idCustomer)
{
DateTime lastDate;
lastDate = (from fp in ge.Payments
from cst in ge.Customers
from brs in ge.Records.AsEnumerable()
where (cst.idCustomer == brs.idCustomer && brs.idHardBox == fp.idHardbox
&& cst.idCustomer == idCustomer)
select fp.datePayment).AsEnumerable().Max();
return lastDate;
}//getLatestPaymentDate
在这里我有另一种方法,它应该调用前一个方法来完成一个 Linq 查询并将其传递给一个 Crystal Report:
//Linq query to retrieve all those customers'data who have not paid their safebox(es) annuity in the last year.
public List<ReportObject> GetPendingPayers()
{
List<ReportObject> defaulterCustomers;
defaulterCustomers = (from c in ge.Customer
from br in ge.Records
from p in ge.Payments
where (c.idCustomer == br.idCustomer
&& br.idHardBox == p.idHardBox)
select new ReportObject
{
CustomerId = c.idCustomer,
CustomerName = c.nameCustomer,
HardBoxDateRecord = br.idHardRecord,
PaymentDate = getLatestPaymentDate(c.idCustomer),
}).Distinct().ToList();
}//GetPendingPayers
这里没有抛出编译错误,但是当我运行应用程序并且第二种方法尝试调用该字段中的第一个方法PaymentDate
时,会出现标题中提到的错误:
Linq to Entities does not recognize the method System.DateTime.. and cannot translate this into a store expression
请任何有有用输入的人让我摆脱这个混乱的错误?任何帮助将不胜感激 !
非常感谢 !