Page 1 of 1

DateTimeOffsets in Entity Model

Posted: Thu 27 Oct 2011 16:31
by TonyV
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?

Tony

P.S.

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?

Posted: Mon 31 Oct 2011 16:33
by Shalex
There is no way to save DateTimeOffset in PostgreSQL correctly: saved and retrieved values will be different in some cases. It was discussed at http://www.devart.com/forums/viewtopic.php?t=20976.

Re: DateTimeOffsets in Entity Model

Posted: Mon 08 Oct 2012 12:17
by bpipe
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.

Re: DateTimeOffsets in Entity Model

Posted: Fri 12 Oct 2012 14:13
by Pinturiccio
dotConnect for PostgreSQL supports DateTimeOffset. You can retrieve it using the GetDateTimeOffset method of the PgSqlDataReader object.
For more information, see here