我一直在阅读一些帖子,但是我没有找到解决方案来解决LINQ To Entities,Lambda Expressions和DateTime.AddMonth
的问题。LINQ to Entities:在Lambda表达式中使用DateTime.AddMonth
的问题是,我试图用DateTime.AddMonth
lambda表达式内,我收到此错误:当我执行这段代码
"LINQ to Entities does not recognize the method 'System.DateTime AddMonths(Int32)' method, and this method cannot be translated into a store expression"
:
List<Orders> orders = context.Orders
.Where(o => o.IdOrderStatus == 1)
.Where(o => o.PaymentDate.Value.AddMonths(o.Products.ProductCategories.CommissionableMonths) > DateTime.Now)
.ToList();
是有一种方法可以避免这种异常,但保持相同的行为?
我对Linq,Lambdas或Entity Framework了解不多。
非常感谢您提前!
Gsus。
是您要添加到PAYMENTDATE月数的o.Products.ProductCategories.Commissionable和值的Int32? – jvanderh 2009-06-30 16:20:59
您应该标记此问题Linq和C# – jvanderh 2009-06-30 16:25:38