這是我的代碼:LINQ與AddMonth方法實體
return Newsletterctx.Subscribers.Count(o =>
o.Validated == false &&
o.ValidationEmailSent == true &&
o.SubscriptionDateTime.AddMonths(1) < DateTime.Now);
我得到這個錯誤:
LINQ to Entities does not recognize the method 'System.DateTime AddMonths(Int32)' method, and this method cannot be translated into a store expression.
在這種情況下,它在聲明testDate變量時拋出異常: System.NullReferenceException:'未將對象引用設置爲對象實例。 CS $ <> 8__locals0爲空。 – 2017-06-21 08:46:30
@İlkinElimov是的,如果序列包含空引用,則可能發生。你可以通過首先用'.Subscribers.Where(o => o!= null).Count(o => ...' – 2017-06-21 08:59:09