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

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM