LLBLGEN Pro v4.2 and NPGSQL v3. Date/Time mappings

Posts   
 
    
Posts: 34
Joined: 22-Oct-2014
# Posted on: 28-Oct-2015 13:29:59   

Hi there!

In my previous posts, we resolved some issues about new Date/Time type mappings in Npgsql v3, but there is one unresolved.

The problem is that we must manually change field mappings of field, with db type time without timezone From System.DateTime to System.TimeSpan every time refreshing the relational model from DB.

We have such table:

CREATE TABLE OperationTime
(
    Id BIGINT NOT NULL DEFAULT new_id() PRIMARY KEY,
    TimeFrom TIME ,
    TimeTo TIME 
);

And for Npgsql to work correctly, it need to be a TimeSpan.

So every time we refreshing project from DB in field mappings of TimeFrom & TimeTo fields LLBLGEN maps it as DateTime. So in runtime we catch errors about Npgsql can not cast field value to DateTime, because it real value has Object(TimeSpan) type.

Errors looks like this:

2015-10-27 00:27:30.7051 [ERROR] SD.LLBLGen.Pro.ORMSupportClasses.ORMValueTypeMismatchException: The value 22:00:00 is of type 'System.TimeSpan' while the field is of type 'System.Nullable`1[System.DateTime]'
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.ValidateValue(IFieldInfo fieldToValidate, Object& value, Int32 fieldIndex)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.SetValue(Int32 fieldIndex, Object value, Boolean performDesyncForFKFields, Boolean checkForRefetch)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityCore`1.SetValue(Int32 fieldIndex, Object value, Boolean checkForRefetch)
   at core.entity.EntityClasses.OperationTimeEntity.set_TimeTo(Nullable`1 value)
   at core.operations.OperationTimeOperation.Create(Int64 operationModeId, Int32 day, String timeFrom, String timeTo, ITransactionContext context)

What must we do to resolve this? And what we must do to every time not to perform magic with manual editting field mappings?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 28-Oct-2015 15:28:27   

On August 27th, we made the change in the driver to map timezone time/dates to different types

PostgreSQL driver: v3 maps Time and Timestamp with Timezone to different types. Mapping tables are adjusted when v3 of npgsql is used.

We map Time to Timespan, and Timetz to DateTimeOffset.

Are you sure you use a driver dated after that date? If the npgsql ado.net provider used at refresh is v2, you'll get the old mapping!

Frans Bouma | Lead developer LLBLGen Pro
Posts: 34
Joined: 22-Oct-2014
# Posted on: 29-Oct-2015 13:49:09   

Are you sure you use a driver dated after that date? If the npgsql ado.net provider used at refresh is v2, you'll get the old mapping!

How to check this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 29-Oct-2015 13:55:05   

When you refresh, the dialog that pops up where you specify the connection parameters has a version number. It should be recent. Also, if you use the latest build of the v4.2 installer, you're using the latest driver and it should automatically map the time typed fields to timestamp IF npgsql v3 is used. It still can be you're using npgsql 2 (I do recall you said you'd go back to that for now due to other issues with npgsql?) and thus have the old mappings.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 34
Joined: 22-Oct-2014
# Posted on: 29-Oct-2015 15:23:01   

Yes, my bad! Used driver from 0925 build. And all is seem to work after reinstalling recent build with 0928 driver version!

Sorry for inconvenience!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 29-Oct-2015 15:30:33   

Glad it's sorted! sunglasses

Frans Bouma | Lead developer LLBLGen Pro