The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity mem

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

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

为了不出现这种状况,有两种解决办法:htm

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

var bdDay = bd.Date;ci

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

2、经过DbFuntions功能方法来转义一下。it

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

相关文章
相关标签/搜索