DateTimeOffsets in Entity Model

DateTimeOffsets in Entity Model

Postby TonyV » Thu 27 Oct 2011 16:31

I've got a Postgres database that contains a number of tables. There are 2 or more "TimeStamp with TimeZone" columns in each table. When Entity Developer builds the classes for these tables, it uses the C# DateTime data type for the properties that correspond to the "TimeStamp with Timezone" columns.

In our C# code, we want to use the DateTimeOffset type, as this preserves the time zone information. (If you use a DateTime to receive the data from the database, it is converted to local time AND THE TIMEZONE IS LOST. We want to keep the time zone offset until we display it, at which time we'll convert to local time.)

How do I get the model to use this data type? Do I have to edit the individual properties?



I tried editing one of the DateTime properties & set it to DateTimeOffset. This didn't work as I got the following message:

Code: Select all
Member Mapping specified is not valid.
The type 'Edm.DateTimeOffset[Nullable=False,DefaultValue=,Precision=]'
of member 'AlarmTime' in type 'LPRCore.CarSystem.Alarm' is not compatible with 'Devart.Data.PostgreSql.timestamptz[Nullable=False,DefaultValue=,Precision=0]'
of member 'AlarmTime' in type 'LPRCore.CarSystem.Store.Alarms'.

How do I make this work?
Posts: 74
Joined: Wed 25 May 2011 15:03

Postby Shalex » Mon 31 Oct 2011 16:33

There is no way to save DateTimeOffset in PostgreSQL correctly: saved and retrieved values will be different in some cases. It was discussed at
Devart Team
Posts: 7659
Joined: Thu 14 Aug 2008 12:44

Re: DateTimeOffsets in Entity Model

Postby bpipe » Mon 08 Oct 2012 12:17

So your ADO .NET PostgreSQL provider doesn't support DateTimeOffset?
Are you going to fix it? I'm not using EF, I use pure ADO .NET it it can't save DateTimeOffset passed as DbParameter, this is kinda strange because I see no problem doing so.
Posts: 17
Joined: Mon 08 Oct 2012 12:14

Re: DateTimeOffsets in Entity Model

Postby Pinturiccio » Fri 12 Oct 2012 14:13

dotConnect for PostgreSQL supports DateTimeOffset. You can retrieve it using the GetDateTimeOffset method of the PgSqlDataReader object.
For more information, see here
Devart Team
Posts: 1983
Joined: Wed 02 Nov 2011 09:44

Return to dotConnect for PostgreSQL