Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to Entities with AddMonth method

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.

like image 459
shlomjmi Avatar asked Aug 20 '10 08:08

shlomjmi


1 Answers

You can use SqlFunctions classvar;

 today =  DateTime.Now; return Newsletterctx.Subscribers.Count(o =>  o.Validated == false &&  o.ValidationEmailSent == true &&  SqlFunctions.DateAdd("month",1,o.SubscriptionDateTime) <today); 
like image 184
whitestream Avatar answered Sep 23 '22 10:09

whitestream