npgsql/EntityFramework6.Npgsql

DateTime.UtcNow is still throwing an exception that says my column needs to be timestamp with time zone, but it is.

ItWorksOnMyMachine opened this issue · 2 comments

All of my datatypes are timezone with time stamp in our database. The model type is DateTime. I'm setting a date value to DateTime.UtcNow in an insert, but am getting this error:

InvalidCastException: Cannot write DateTime with Kind=UTC to PostgreSQL type 'timestamp without time zone', consider using 'timestamp with time zone'. Note that it's not possible to mix DateTimes with different Kinds in an array/range. See the Npgsql.EnableLegacyTimestampBehavior AppContext switch to enable legacy behavior.

I tried setting a ColumnAttribute on the column to Column(TypeName="timestamptz") and am getting this error:
MappingException: Schema specified is not valid. Errors:
(8329,12) : error 2019: Member Mapping specified is not valid. The type 'Edm.DateTime[Nullable=False,DefaultValue=,Precision=]' of member 'CreatedDate' in type 'CodeFirstNamespace.TemporaryJoiner' is not compatible with 'Npgsql.timestamptz[Nullable=False,DefaultValue=,Precision=7]' of member 'createddate' in type 'CodeFirstDatabaseSchema.TemporaryJoiner'.

You must use "AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);" if upgraded to version 6.0.x of the provider.

roji commented

The EF6 provider is no longer being actively maintained (just like EF6 itself). It's not recommended to run it with newer versions of the Npgsql ADO.NET driver: these haven't been tested and make break in various way.

Consider staying on the version of Npgsql that's referenced by the EF6 provided instead.