使用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));