DbArithmeticExpression 参数必须具有数字公共类型.实体框架

本文关键字:类型 实体 框架 数字 参数 DbArithmeticExpression | 更新日期: 2023-09-27 18:31:29

我有一个MVC应用程序,我想根据我的要求从sql服务器数据库中获取记录。主要是我有表格"办公室详细信息",其中一列是"批准日期",第二列是"儿童计数"。"已批准"包含用户文档获得批准的日期。第二个"子计数"包含整数值。我还在这个网站上搜索了另一个问题,但没有得到解决方案。我正在使用两个 where 条件,所以为了记录,我写了这段代码。

 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();
    }

DbArithmeticExpression 参数必须具有数字公共类型.实体框架

问题似乎是XTimeSpend的计算,因为您需要使用sqlfunctions来减去日期

好的,终于我得到了,我必须做出这样的改变,

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();