0

初めて比較してみた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)
};

それは正常に動作します。私の質問は..これらの違いは何ですか??

4

2 に答える 2

0

メッセージ

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.

かなり自明です。SQL は、DateTime 型の Date プロパティを取得する方法を知りません。DateTime で動作します。整数で動作します。あなたの場合、整数で動作させる必要があります。

パフォーマンスに関する限り..悪い影響は見られません。

PS: DateSQL でのデータ型のサポートは、これとは関係ありません。

于 2013-06-26T08:15:19.497 に答える