DateTime.Kind ignored when writing to database

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
Posts: 4
Joined: Wed 29 Jun 2016 13:34

DateTime.Kind ignored when writing to database

Post by » 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.

Devart Team
Posts: 7964
Joined: Thu 14 Aug 2008 12:44

Re: DateTime.Kind ignored when writing to database

Post by Shalex » Thu 07 Jul 2016 11:37

We recommend you to use Entity Developer (Devart Entity Model, *.edml) instead of EDM Designer (ADO.NET Entity Data Model, *.edmx) because it is adjusted for working with PostgreSQL and has an advanced functionality: Additionally, Entity Developer supports DateTimeOffset.

You can migrate your existing *.edmx to *.edml, just open *.edmx with Entity Developer and save model (as *.edml). Entity Developer allows only to import *.edmx but the output would be *.edml. Output can not be *.edmx because Entity Developer uses extra tags and attributes, additional features which are not supported by EDM Designer.

Does this help?

Post Reply