DbArithmeticExpression arguments must have a numeric common type


When I am trying to run this command using Entity framework in controller of my project

var userContext =context.UserExtraDetails.Where(a => (DateTime.Now - a.LastEmailSent.Value).TotalDays >= 6)
.Select(a => new { Id = a.AspNetUser.Id, 
email = a.AspNetUser.Email,
Fullname = a.AspNetUser.FirstName + " " + a.AspNetUser.LastName
 }).ToList();

I am getting an error "DbArithmeticExpression arguments must have a numeric common type"

Values are not null, but not sure what is the issue.

 


Asked by:- jaya
1
: 335 At:- 5/30/2017 11:30:37 AM
C# Linq Entity Framework






1 Answers
profileImage Answered by:- vikas_jk

Arithmetic with DateTime is not supported in Entity Framework.
You cannot use subtraction in a query: the operator - is overloaded in .NET, but not in the SQL Server.

you can SqlFunctions.DateDiff for your code so it will be like

var Usernotsent = context.UserExtraDetails
.Where(a => System.Data.Entity.SqlServer.SqlFunctions.DateDiff("day", a.LastEmailSent.Value, DateTime.Now) > 6)
.Select(a => new { 
Id = a.AspNetUser.Id,
 email = a.AspNetUser.Email,
 Fullname = a.AspNetUser.FirstName + " " + a.AspNetUser.LastName,
 EmailSub = a.EmailSubscribe,
lastsent = a.LastEmailSent })
.ToList();
2
At:- 5/30/2017 3:19:15 PM
great, I wasn't aware of that.thank you 0
By : jaya - at :- 5/31/2017 9:04:34 AM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use