問題: 記録日が 2 つの日付 (mm/dd/yyyy) の間にあるものをユーザーが検索できる検索フォームがあります。
すべてのレコードとオブジェクトは Datetime 型ですが、比較する必要があるのは時刻部分ではなく日付部分だけです。
MSDN によると、Date プロパティは LINQ でサポートされていますが、このステートメントではラムダ部分に .Date を追加できません。
エラー:
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
例:
x.DateCreated.Date
この問題はよくあると思います - どうすれば解決できますか?
<= 部分に 23:59:59 = 86399 秒を追加することで、他の日付を埋めることができると思います
これが声明です。(db はコンテキスト オブジェクトです)
model.Contacts =
db.Prospects.Where(x => x.DateCreated >= df.Date && x.DateCreated <= dt.Date)
.OrderByDescending(x => x.DateCreated)
.Take(100)
.ToList();