gpt4 book ai didi

c# - 使用 AddMonth 方法的 LINQ to Entities

转载 作者:IT王子 更新时间:2023-10-29 04:20:12 36 4
gpt4 key购买 nike

这是我的代码:

 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.

最佳答案

您可以使用 SqlFunctions 类变量;

 today =  DateTime.Now; return Newsletterctx.Subscribers.Count(o =>
o.Validated == false &&
o.ValidationEmailSent == true &&
SqlFunctions.DateAdd("month",1,o.SubscriptionDateTime) <today);

关于c# - 使用 AddMonth 方法的 LINQ to Entities,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3529361/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com