DateTime.Kind ignored when writing to database
Posted: Tue 05 Jul 2016 22:49
I am using Entity Framework EDM model with dotConnect for PostgreSQL. One of the entity properties is of type DateTime and maps to a timestamptz column in the database. I can't use DateTimeOffset because EDM doesn't support that mapping.
If I assign a DateTime with Kind = Utc to the property, the Kind is ignored when the data is stored to the database.
For example, if I have a DateTime '2016-04-01 22:10' and Kind = Utc, it ends up in the database as '2016-04-01 22:10 -6' (I'm in Mountain tz). When I later query it, the property is now a DateTime '2016-04-01 22:10' with Kind = Local, which is incorrect.
Is it supposed to work this way? I saw an old post that seemed related, but it was about Kind being dropped on reading the data, not writing it.
If I assign a DateTime with Kind = Utc to the property, the Kind is ignored when the data is stored to the database.
For example, if I have a DateTime '2016-04-01 22:10' and Kind = Utc, it ends up in the database as '2016-04-01 22:10 -6' (I'm in Mountain tz). When I later query it, the property is now a DateTime '2016-04-01 22:10' with Kind = Local, which is incorrect.
Is it supposed to work this way? I saw an old post that seemed related, but it was about Kind being dropped on reading the data, not writing it.