我有一个问题需要花费数周才能解决,而我一直无法解决。Linq to Entities不能识别方法System.DateTime ..并且无法将其转换为商店表达式
我有一个类,我有两种方法。以下是应该从数据库中获取最新日期。这个日期代表客户做了以“东西”最新的支付:
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报告:
//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
请有人提供一个有用的输入,使我从这个凌乱的错误?任何帮助将不胜感激 !
非常感谢!
嗨,感谢您的输入,但我真的无法完成这项工作。你说你提供的第二个问题是最简单的,但是我不明白它是如何解决我的问题的,因为我已经声明了一个DateTime类型的变量并将其解析为假设的日期,但仍然不起作用。你能再解释一下吗?我将非常感激! – 2013-03-14 22:26:58
请检查我上面的评论。非常感谢! – 2013-03-15 13:47:59
当然!简单地说:'getLatestPaymentDate'没有SQL等价物。我会编辑我的答案,以便更明确地说明你可以做什么。 – SolarBear 2013-03-15 14:38:25