我第一次嘗試比較DateTime
錯誤比較日期時間
var searchResult = new PagedData<SAMPLE_STOCK>
{
Data = _db.SAMPLE_STOCK.Where(m => m.LAST_UPDATED.Date == lastUpdate.Date)
};
return PartialView(searcReasult);
它提供了以下錯誤
The specified type member 'Date' is not supported in LINQ to
Entities. Only initializers, entity members, and entity navigation
properties are supported.
然後我寫下面的代碼
var searchResult = new PagedData<SAMPLE_STOCK>
{
Data = _db.SAMPLE_STOCK.Where(m => m.LAST_UPDATED.Day == lastUpdate.Day
&& m.LAST_UPDATED.Month == lastUpdate.Month
&& m.LAST_UPDATED.Year==lastUpdate.Year)
};
它工作正常。我的問題是......這些有什麼區別?
閱讀此:http://stackoverflow.com/questions/16736252/using-datetime-in-linq-to-entities –
可能的重複:http://stackoverflow.com/questions/7320608/simple-way-to -compare-日期功能於日期時間屬性-使用實體框架-4-及-1- – Abbas