Giorgi / DuckDB.NET

Bindings and ADO.NET Provider for DuckDB
https://duckdb.net
MIT License
436 stars 70 forks source link

Can't query Dates with Dapper `Object must implement IConvertible` #227

Open MeltyObserver opened 1 day ago

MeltyObserver commented 1 day ago

When trying to query a row with a Date column using dapper i get Object must implement IConvertible but it works fine with ADO.Net

Full exception:

``` Error parsing column 2 (creationDate=11/14/2024 - Object) -------------- System.InvalidCastException: Object must implement IConvertible. at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Deserializebf872d3d-40a6-4be7-bb5e-31af6c01baa4(DbDataReader) -------------- at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in /_/Dapper/SqlMapper.cs:line 3928 at Deserializebf872d3d-40a6-4be7-bb5e-31af6c01baa4(DbDataReader) at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) at Program.
$(String[] args) ```

I wrote an example project that can reproduce the bug https://github.com/MeltyObserver/DDB.NET.Examples

Giorgi commented 22 hours ago

Try changing the property to DateOnly

MeltyObserver commented 22 hours ago

with DateOnly dapper crashes on insert

code:

cn.Execute("INSERT INTO files (title, creationDate) VALUES ($title, $date)",
        new { title = file.Title, date = file.CreationDate });

error:

Unhandled exception. System.NotSupportedException: The member date of type System.DateOnly cannot be used as a parameter value
   at Dapper.SqlMapper.LookupDbType(Type type, String name, Boolean demand, ITypeHandler& handler) in /_/Dapper/SqlMapper.cs:line 497
   at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity, Boolean checkForDuplicates, Boolean removeUnused, IList`1 literals) in /_/Dapper/SqlMapper.cs:line 2656
   at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache) in /_/Dapper/SqlMapper.cs:line 1848
   at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in /_/Dapper/SqlMapper.cs:line 654
   at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in /_/Dapper/SqlMapper.cs:line 527
   at Program.<Main>$(String[] args) in Program.cs:line 26
Giorgi commented 22 hours ago

Try this: https://github.com/DapperLib/Dapper/issues/1715#issuecomment-1149665776

MeltyObserver commented 22 hours ago

That does work, I thought the issue was from this library because i didn't have an issue with postgres (npgsql)

is it possible to add this to the library?