这是我的代码: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