Rahul Chaudhari
Rahul Chaudhari

Reputation: 148

DbArithmeticExpression arguments must have a numeric common type. Entity framework

I have One MVC Application, In that I want to grab record from sql server database as per my requirement. Mainly I have Table "OfficeDetail" in that One column is "ApprovedDate" and Second is "ChildCount". "Approvedate" contain a date of when user's document was approved. Second "ChildCount" contain Integer Value. I also searched another question on this site,but didnt get solution. I am using two where conditions, So for get record i written this code.

 public IEnumerable<EmployeeModel> GetAllExpired()
    {
        DateTime my = DateTime.Today;

        DBContext = new ConsumerNomineeFormEntities();
        return (from f in DBContext.OfficeDetails

               where (SqlFunctions.DateDiff("second",f.Date,my.Date)>90)
               where (f.ChildCount>5)
                select new EmployeeModel
                    {
                        XConsumer_Id = f.ConsumerNo_,
                        XApproved = f.Date,
                        XChildCount = f.ChildCount,
                        XTimeSpent = (f.Date - DateTime.Today).TotalDays
                    }).ToList();
    }

Upvotes: 0

Views: 2385

Answers (2)

Rahul Chaudhari
Rahul Chaudhari

Reputation: 148

Ok, finally i got , I have to make changes like this ,

DBContext = new ConsumerNomineeFormEntities();
        return (from f in DBContext.OfficeDetails
                where SqlFunctions.DateDiff("day", f.Date, my.Date) > 90
                where f.ChildCount < 5
                select new EmployeeModel
                    {
                        XConsumer_Id = f.ConsumerNo_,
                        XApproved = f.Date,
                        XChildCount = f.ChildCount,
                        XTimeSpent = SqlFunctions.DateDiff("day", f.Date, my.Date)
                    }).ToList();

Upvotes: 0

tede24
tede24

Reputation: 2354

The problem seems to be the computation of XTimeSpent as you need to use sqlfunctions to subtract dates

Upvotes: 2

Related Questions