- System.NotSupportedException: The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.【LINQ to Entities不支援類型成員‘Date’,僅支援初始化器,實體成員和實體導航屬性】
錯誤是這樣出來的:
query = query.Where(a => a.StatDate.HasValue && a.StatDate.Value ==System.DateTime.Now.Date);
搞來搞去,有人說要用DbFunctions.TruncateTime這個方法先對要對比的值進行處理什麼的,其實好像都不行,其實好像并不是這樣,其實是System.DateTime.Now.Date這個東東不應該出現在
using (XLShouYouEntites db = new XLShouYouEntites())
{
}
之間,如果在這個之前就定義一個變量:
DateTime today = System.DateTime.Now.Date;
然後在這個using之間使用這個today變量就不會有問題了,應該是因為EF不具有這些功能,不能完成 LINQ to Entities的轉換。