Skip to content

Conversation

@DeagleGross
Copy link
Collaborator

@DeagleGross DeagleGross commented Sep 21, 2024

In .NET6 DateOnly and TimeOnly were introduced. Current PR proposes support for those in Dapper.AOT.

I performed testing against MsSql and PostgreSql. Check DateOnlyTimeOnlyTests.cs for validating how data is being parsed from database via System.Data.Common.DbDataReader.

Here is how data is parsed and how I convert it:

SQL db-type c# type DbDataReader.GetValue() returns how converted notes
Postgre timestamp DateTime DateTime Convert.ToDateTime() ...
MsSql datetime DateTime DateTime Convert.ToDateTime() the only difference between Postgre and MsSql - name of "timestamp" type
Postgre timestamp DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime() ...
Postgre timestamp TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() ...
-------
Postgre date DateTime DateTime Convert.ToDateTime() technically date is a datetime as well, so left as is
Postgre date DateOnly DateTime Convert.ToDateTime() -> DateOnly.FromDateTime()
Postgre date TimeOnly DateTime Convert.ToDateTime() -> TimeOnly.FromDateTime() will always return default(TimeOnly). Dont know if it is better to explicitly throw here?
-------
Postgre time DateTime TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateTime
Postgre time DateOnly TimeSpan Convert.ToDateTime() throws InvalidCastException TimeOnly can't be a DateOnly
Postgre time TimeOnly TimeSpan cast object arg to TimeSpan -> TimeOnly.FromTimeSpan()

I have adjusted the implementation of CommandUtils.As<T> according to the table above, and then wrote integration tests (only for postgreSql).

Note: I also wrote a code to exclude non-compatible input files for unit Interceptors tests (we dont need to run .netFx tests against DateOnly.input.cs, because .netFx does not support DateOnly and TimeOnly types).

Closes #116

@DeagleGross DeagleGross self-assigned this Sep 21, 2024
@mgravell mgravell merged commit d162ec9 into DapperLib:main Feb 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support DateOnly that was added in Dapper 2.1.37

2 participants