剣道UIを使用してasp.net MVCシステムを開発しています。私はビューのフィルタボタンから "日付"をコントローラに送信し、LINQをフィルタリングする必要があります。私はこのコードを使用しました:null可能なdatetimeをLINQ asp.net MVCの文字列に変換中にエラーが発生しました。
public ActionResult Grid_ReadLogAdminList([DataSourceRequest] DataSourceRequest request, string filterDate)
{
DateTime _temp;
if (!DateTime.TryParse(filterDate, out _temp))
_temp = DateTime.Now;
return Json(_context.Entities<LogAdmin>().NoTracking().OrderByDescending(l => l.TimeStamp)
.Where(f => f.TimeStamp.Value.ToString("dd.MM.yyyy") == _temp.ToString("dd.MM.yyyy"))
.Select(l => new LogAdminInfo
{
Id = l.Id,
Message = l.Message,
MessageTemplate = l.MessageTemplate,
Level = l.Level,
TimeStamp = l.TimeStamp,
Exception = l.Exception,
Properties = l.Properties,
LogEvent = l.LogEvent,
})
.ToDataSourceResult(request));
}
しかし、それは私に ".Where"のエラーを与えました。 TimeStampフィールドが "datetime"であることを知っておく必要があります。 null可能なdatetime。
私はこのエラーを受け取っ:
LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.
は、どのように私は、エラーを修正できますか?
あなたが最初にあなたの日付を確認する必要があるがnullの場合か否か。 –
私はそれをやろうとしました。 ( "d.d.MM.yyyy")):== _temp.ToString( "dd.MM.yyyy"))。 ...うまくいきませんでした –
T-SQLに変換できなかったため、Linqがエンティティに認識できませんでした。ここをクリックしてください:http://stackoverflow.com/a/34061692/2946329 –