SqlMapper.TypeHandler<DateTime?> not working with SQLite
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the SQLite schema and Dapper Query behavior described in the issue, then inspect SqlMapper.AddTypeHandler and the nullable DateTime TypeHandler SetValue and Parse entry points. Compare this with the working nullable DateTimeOffset case; done means explaining or correcting why the DateTime handler is not invoked and verifying the result with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sqlite
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100