• Linq to sql中使用DateDiff()


     Linq to sql中使用DateDiff()

    计算时间差的方法

    第一种办法:

    from p in PurchaseLists where EntityFunctions.DiffDays(p.CreateTime,DateTime.Now) >=(p.DayLen/2) select p

    报错:System.NotSupportedException: LINQ to Entities 不识别方法“System.Nullable`1[System.Int32] DiffDays(System.Nullable`1[System.DateTime], System.Nullable`1[System.DateTime])”,因此该方法无法转换为存储表达式。

    第二种方法:

    PurchaseLists.Where(t=>(DateTime.Now-t.CreateTime).Days>=p.DayLen/2)

    报错 DbArithmeticExpression参数必须具有数值通用类型

    这时候,就是因为你使用的是EF6框架。上面两种方法都不行。

    将EntityFunctions.DiffDays()替换为System.Data.Entity.DbFunctions.DiffDays()方法

    就可以了。。。。

  • 相关阅读:
    云计算-MapReduce
    云计算--hbase shell
    云计算--hdfs dfs 命令
    云计算--MPI
    jQuery 效果
    jQuery 效果
    JQuery效果隐藏/显示
    JQuery教程
    六级啊啊啊
    jQuery 安装
  • 原文地址:https://www.cnblogs.com/melodygkx/p/10177440.html
Copyright © 2020-2023  润新知