Dapper icon indicating copy to clipboard operation
Dapper copied to clipboard

SqlMapper.TypeHandler<DateTime?> not working with SQLite

Open ImGonaRot opened this issue 7 years ago • 2 comments

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?

ImGonaRot avatar Apr 15 '17 23:04 ImGonaRot

Same problem

agnusha avatar Dec 11 '20 13:12 agnusha

same problem

AmirMahdyJebreily avatar Sep 24 '23 14:09 AmirMahdyJebreily