【问题标题】:DbArithmeticExpression arguments must have a numeric common type. Entity frameworkDbArithmeticExpression 参数必须具有数字通用类型。实体框架
【发布时间】:2016-01-23 05:05:02
【问题描述】:

我有一个 MVC 应用程序,我想根据我的要求从 sql server 数据库中获取记录。主要是我有表“OfficeDetail”,其中一列是“ApprovedDate”,第二列是“ChildCount”。 “批准”包含批准用户文档的日期。第二个“ChildCount”包含整数值。我还在这个网站上搜索了另一个问题,但没有得到解决方案。我使用了两个 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();
    }

【问题讨论】:

    标签: c# entity-framework datetime


    【解决方案1】:

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

    【讨论】:

    • thnx .. 但是直到我有一个问题根据我的 where 条件我在表中有一个记录,其批准日期是 2015-08-20 并且 childcount 是 3 ,因此这个日期和今天的日期超过 90 天。但是当我有一条记录时,我的屏幕上没有任何记录
    • 好的,但是为什么不将此答案标记为已解决?您的问题描述是关于异常的,并且通过这个答案解决了..
    • 因为你的答案不是完美的解决方案......但我给予你的荣誉......而我的......
    【解决方案2】:

    好吧,我终于明白了,我必须做出这样的改变,

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

    【讨论】:

      猜你喜欢
      • 2012-04-06
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 1970-01-01
      • 2020-10-27
      • 2015-07-04
      相关资源
      最近更新 更多