LINQ与AddMonth方法实体 [英] LINQ to Entities with AddMonth method
本文介绍了LINQ与AddMonth方法实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的code:
返回Newsletterctx.Subscribers.Count(O = GT;
o.Validated ==假放;&安培;
o.ValidationEmailSent ==真&功放;&安培;
o.SubscriptionDateTime.AddMonths(1) - ; DateTime.Now);
我得到这个错误:
LINQ到实体无法识别
方法的System.DateTime
AddMonths(Int32)已的方法,这
方法不能被翻译成
店前pression。
块引用>解决方案也许你可以转移的日期再次进行测试,而不是:
的DateTime testDate = DateTime.Now.AddMonths(-1);
返回Newsletterctx.Subscribers.Count
(O => o.Validated ==假
&功放;&安培; o.ValidationEmailSent ==真
&功放;&安培; o.SubscriptionDateTime< testDate);This is my code:
return Newsletterctx.Subscribers.Count(o => o.Validated == false && o.ValidationEmailSent == true && o.SubscriptionDateTime.AddMonths(1) < DateTime.Now);
I get this error:
LINQ to Entities does not recognize the method 'System.DateTime AddMonths(Int32)' method, and this method cannot be translated into a store expression.
解决方案Perhaps you can shift the date to test against instead:
DateTime testDate = DateTime.Now.AddMonths(-1); return Newsletterctx.Subscribers.Count (o => o.Validated == false && o.ValidationEmailSent == true && o.SubscriptionDateTime < testDate);
这篇关于LINQ与AddMonth方法实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文