• The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.


    使用EF时,在Limda表达式中( query.Where(x => x.CheckInDate >= bd.Date);)查询的时候抛出了这个异常,网上查到的发现,并不能解决问题。

    后来,在 http://sandeep-tada.blogspot.com/2014/02/the-specified-type-member-date-is-not.html  中发现,原来Linq中不允许使用DateTime成员Date     

    为了避免出现这种情况,有两种解决办法:

    一、将bd.Date在Linq外部赋值后再传入:

    var bdDay = bd.Date;

     query.Where(x => x.CheckInDate >= bdDay );

    二、通过DbFuntions功能方法来转义一下。

     query.Where(x => x.CheckInDate >= DbFunctions.TruncateTime(bd.Date)); 

  • 相关阅读:
    Unreal中的python开发
    2022.5.16
    2022.5.18
    2022.5.4
    2022.5.2
    2022.5.6
    2022.5.14
    2022.4.30
    2022.5.10
    2022.5.8
  • 原文地址:https://www.cnblogs.com/atwind/p/8446912.html
Copyright © 2020-2023  润新知