I am trying to invalidate requests of friendship that were reponded less than 30 days ago.
var requestIgnored = context.Request
.Where(c => c.IdRequest == result.IdRequest
&& c.IdRequestTypes == 1
&& c.Accepted == false
&& DateTime.Now <= (((DateTime)c.DateResponse).AddDays(30)))
.SingleOrDefault();
c.DateResponse
is of type DateTime?
. The error I am having is :
LINQ does not recognize the command .AddDays
Edit: If you're using EntityFramework >= 6.0, use DbFunctions.AddDays
. For older versions of Entity Framework, use EntityFunctions.AddDays
:
var requestIgnored = context.Request
.Where(c => c.IdRequest == result.IdRequest
&& c.IdRequestTypes == 1
&& c.Accepted == false
&& DateTime.Now <= DbFunctions.AddDays(c.DateResponse, 30))
.SingleOrDefault();
You might try this:
var thirtyDaysAgo = DateTime.Now.AddDays(-30);
var requestIgnored = context.Request
.Where(c =>
c.IdRequest == result.IdRequest &&
c.IdRequestTypes == 1 &&
c.Accepted == false &&
c.DateResponse.HasValue &&
thirtyDaysAgo <= c.DateResponse.Value)
.SingleOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With