Question

Is there any way to specify Entity Framework to convert all DateTime in UTC (for azure database storage) ?

I would like that my model stay in local date time. I don't want to duplicate model datetime properties to have one in UTC (for EF) and another one in local (for my views, not mapped in EF).

Popular Answer

Take a look at DateTimeOffset introduced in .Net 4.5 - this stores timezone information as the datetimeoffset SQL type (both SQL Server 2008+ and Azure Database Storage).

By using DateTimeOffset, you do not need to worry anywhere near as much about time zones, which should let you still work in local time for your model.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why