私はSystem.NotSupportedException
使用していDateTime
ますか?でLinq to Entities
。
私の元の方法は次のようになります。
public TransportOrderLine GetLastTransportOrderLine(bool isDriver, int? driverId, int? haulierId , DateTime date, IDatabaseContext db)
{
var lines =
db.Query<TransportOrderLine>()
.Where(x => ((isDriver && x.TransportOrder.DriverId == driverId) ||
(!isDriver && x.TransportOrder.HaulierId == haulierId)) &&
x.StartDatePlanned.HasValue &&
EntityFunctions.TruncateTime(x.StartDatePlanned) <= date)
.ToList();
return lines.OrderByDescending(x => x.TransportOrder.Sequence)
.ThenByDescending(x => x.Sequence).LastOrDefault();
}
なんらかの理由で、NotSupportedException
linq to entities がDateTime
パーツを実行するときに例外 ( ) が発生します。
TransportOrderLine.StartDatePlanned
は ? 型DateTime
です。
また、コードを次のように分割しました。
var lines = db.Query<TransportOrderLine>()
.Where(x => ((isDriver && x.TransportOrder.DriverId == driverId) ||
(!isDriver && x.TransportOrder.HaulierId == haulierId)))
.ToList(); //ok
lines = lines.Where(x => x.StartDatePlanned.HasValue).ToList(); //ok
lines = lines.Where(x => EntityFunctions.TruncateTime(x.StartDatePlanned)<= date)
.ToList(); //error here
私もこれを試しました:
lines = lines.Where(x => (DateTime)EntityFunctions
.TruncateTime((DateTime)x.StartDatePlanned.Value)
.Value <= date).ToList(); //error here
誰でも解決策を知っています。
ご清聴ありがとうございました:)