DapperLib / DapperAOT

Build time tools in the flavor of Dapper
Other
346 stars 19 forks source link

Support DateOnly that was added in Dapper 2.1.37 #116

Open Dean-NC opened 3 months ago

Dean-NC commented 3 months ago

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'

mgravell commented 1 week ago

Core bits:

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 commented 1 week ago

@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