Dapper
Dapper copied to clipboard
SqlMapper.TypeHandler<DateTime?> not working with SQLite
I have a SQLite database with a table that has a column defined as the following:
CreatedDate DateTime DEFAULT (date('now')),
While using Dapper Execute command, I can insert a new record just fine with with or without CreatedDate BUT if I try to use Dapper Query either with a class or dynamic it will throw an error saying the following:
String was not recognized as a valid DateTime.
So I then proceeded to create a new SqlMapper.TypeHandler<DateTime?> like the following: https://github.com/StackExchange/Dapper/issues/295
I added
Dapper.SqlMapper.AddTypeHandler(new NullableDateTimeHandler.Default);
But the NullableDateTimeHandler SetValue and Parse never get called.
I then went into SQLite I changed the CreatedDate to a DateTimeOffet
CreatedDate DateTimeOffest DEFAULT (date('now')),
Which is not a know SQLite data type.
And then change the TypeHandler<DateTimeOffset?>...
Then it works.
So for some reason I can't get SqlMapper.TypeHandler<DateTime?> to work with SQLite but I can get it to work with custom types "aka DateTimeOffset?".
What am I doing wrong?
Same problem
same problem