Npgsql 10 breaking changes DateOnly, TimeOnly

Posts   
 
    
mbp
User
Posts: 30
Joined: 03-Jun-2021
# Posted on: 26-Nov-2025 09:08:34   

Hi,

Npgsql 10 release notes say:

date and time are now mapped to DateOnly and TimeOnly The PostgreSQL date and time types are now read as .NET DateOnly and TimeOnly, instead of DateTime and TimeSpan by default, respectively. This affects non-generic read methods which return object, such as ExecuteScalarAsync and NpgsqlDataReader.GetValue; you can still read DateTime and TimeSpan via the generic GetFieldValue.

When upgrading existing code base, my entities that have e.g. a date type, will fail when accessing the property on the entity:

System.InvalidCastException: Unable to cast object of type 'System.DateOnly' to type 'System.DateTime'.

Is it possible that LLBLGen could get DateOnly/TimeOnly support, or use the generic GetFieldValue to avoid this cast exception?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39997
Joined: 17-Aug-2003
# Posted on: 27-Nov-2025 08:12:26   

We're looking into adding that for the next version (also for sql server). However atm this isn't possible so if you can use a npgsql 9.x version till then that would be the best option. If you really need to use npgsql 10, you have to define a System.DateOnly and System.TimeOnly type (can be empty) in the Postgresql driver (sourcecode is on our website under My Account -> Downloads -> version -> Extras section), and then specify these types in the mapping table in the Driver main file for date and time. The designer is a .net framework app so System.DateOnly/TimeOnly aren't available hence you have to define them yourself. Additionally you have to define a typeshortcut for these two types. The code generator should use the textual type string in the output so in the end it should work out fine.

GetFieldValue is really slow so we don't use that.

(edit) looks like they added a switch in the past few days: https://github.com/npgsql/npgsql/pull/6359 based on feedback in issue https://github.com/npgsql/npgsql/issues/6349. Their 'move fast and break things' approach similar to the asp.net team isn't really working in database land. Backwards compatibility is key.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39997
Joined: 17-Aug-2003
# Posted on: 27-Nov-2025 16:20:40   

We've implemented support for this for 5.13 for Postgresql.

Frans Bouma | Lead developer LLBLGen Pro