William William - 1 year ago 172
C# Question

How to specify that DateTime objects retrieved from EntityFramework should be DateTimeKind.UTC

I have C# program where all

objects are
. When saving the objects to the database it stores UTC as expected. However, when retreiving them, they are
. Is there a way to tell Entity Framework (Code First) when creating
objects in C# to always use

Answer Source

No, there's not. And it's actually DateTimeKind.Unspecified.

However, if you are concerned about supporting multiple timezones, you should consider using DateTimeOffset. It's like a regular DateTime, except that it does not represent a "perspective" of time, it represents an absolute view, in which 3PM (UTC - 3) equals 4PM (UTC - 2). DateTimeOffset contains both the DateTime and the time zone and it's supported by both EntityFramework and SQL Server.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download