var filtered = new NORTHWNDEntities().Orders.Where(x => x.OrderDateLocal == new System.DateTime(1996, 7, 4)).Decompile().ToList();
fails with
An unhandled exception of type 'System.NotSupportedException' occurred in EntityFramework.SqlServer.dll
Additional information: LINQ to Entities does not recognize the method 'System.DateTime ToLocalTime()' method, and this method cannot be translated into a store expression.
I could achieve somewhat by doing this:
public partial class Order
{
public DateTime OrderDate { get; set; }
[Computed]
public DateTime OrderDateLocal => DbFunctions.AddMinutes(OrderDate, someOffSetValue);
}
but this doesn't handle DST as far as I understand.
Say I have a DateTime property coming from DB which is in UTC. I would like to display it in local time in front-end. E.g.
My EF query would look like,
I would like subsequent
OrderBy
andWhere
onquery
to be based onOrderDateLocal.ToUniversalTime
.The advantage of ToLocalTime and ToUniversalTime are that they take care of DST conversion if any.
For e.g. my query,
fails with
I could achieve somewhat by doing this:
but this doesn't handle DST as far as I understand.