Linq to Entities でクエリを作成しようとしています。クエリしているテーブルの文字列から派生した DateTime プロパティを含むオブジェクトを返すようにします。(SQL Server の) データには、date_occurred という文字列の日付フィールド (データベースでは VARCHAR(8) として表示されます) があります。time_occurred と呼ばれる文字列時間フィールド (varchar(6)) があります。
date_occurred の内容の例は、2013 年 10 月 7 日を表す "20131007" です。time_occurred の内容の例は、午後 2 時 57 分から 10 秒を意味する "145710" です。
うまくいかない2つの方法を試しました:
Dim ATQuery = From e In EntityContext.vwSecAppAuditToday
Order By e.date_occurred, e.time_occurred
Select New AuditEntry With {
.EventTime = DateTime.ParseExact(Trim(e.date_occurred) & Trim(e.time_occurred), "yyyyMMddHHmmss", CultureInfo.InvariantCulture),
.ServerName = e.server_name
}
これNotSupportedException
により、次のメッセージがスローされます。
その前に、私は試しました:
Dim ATQuery = From e In EntityContext.vwSecAppAuditToday
Order By e.date_occurred, e.time_occurred
Select New AuditEntry With {
.EventTime = New DateTime(Integer.Parse(e.date_occurred.Substring(0, 4)),
Integer.Parse(e.date_occurred.Substring(4, 2)),
Integer.Parse(e.date_occurred.Substring(6, 2)),
Integer.Parse(e.time_occurred.Substring(0, 2)),
Integer.Parse(e.time_occurred.Substring(2, 2)),
Integer.Parse(e.time_occurred.Substring(4, 2))),
.ServerName = e.server_name
}
これも をスローしNotSupportedException
ます。この場合、「LINQ to Entities ではパラメーターなしのコンストラクターと初期化子のみがサポートされています」というメッセージが表示されます。
Linq to Entities を使用して私がやろうとしていることは可能ですか?
編集:コメントアラート
後でこの投稿を読む人のために、Moho と Matt Johnson が特に役立つコメントを寄せています。これらを+1でマークしました。