Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DateOnly that was added in Dapper 2.1.37 #116

Open
Dean-NC opened this issue Mar 21, 2024 · 2 comments · May be fixed by #129
Open

Support DateOnly that was added in Dapper 2.1.37 #116

Dean-NC opened this issue Mar 21, 2024 · 2 comments · May be fixed by #129
Assignees
Labels
enhancement New feature or request

Comments

@Dean-NC
Copy link

Dean-NC commented Mar 21, 2024

I'd like to use DateOnly since it was added to Dapper 2.1.37, but AOT 1.0.31 throws an error when using it with queries like IDbConnection.QueryAsync

InvalidCastException: Invalid cast from 'System.DateTime' to 'System.DateOnly'

@Dean-NC Dean-NC added the enhancement New feature or request label Mar 21, 2024
@mgravell
Copy link
Member

mgravell commented Jul 5, 2024

Core bits:

  • test a DTO type in and out with DateOnly and (separately) TimeOnly
  • setting parameter values will probably "just work"
  • reading values needs to be sure to use the <T> version of GetValue
  • reading output / inputoutput parameter values might need love

Note that it requires provider support; it will not work on System.Data.SqlClient; it should work on recent Microsoft.Data.SqlClient and NpgSql

@Dean-NC
Copy link
Author

Dean-NC commented Jul 5, 2024

@mgravell I use Microsoft.Data.SqlClient and SQL Server 2019. The issue is only with querying, not inserting.

Here's a tiny project that reproduces it using Dapper 2.1.37, AOT 1.0.31, Microsoft.Data.SqlClient 5.2.1. The table has a Date column, and the DTO a corresponding DateOnly property.

DapperAotDateOnly.zip

Run CreateTable.sql, and in Program.cs change dbName constant to your db name.

Aot-DateOnly-Error1
Aot-DateOnly-Error2

@DeagleGross DeagleGross linked a pull request Sep 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants