Mapping for DateTime2
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I use datetime2 in SqlServer to store datetimes with increased accuracy, because the legacy datetime gets rounded on nanoseconds (note also that Microsoft themselves recommend the replacement)
And to get this working in Dapper I had to update its mappings with
typeMap[typeof(DateTime)] = DbType.DateTime2;
...
typeMap[typeof(DateTime?)] = DbType.DateTime2;
Legacy datetime columns continue to work with the above, because SQL Server has an implicit convertsion from datetime2 to datetime so all seems fine.
Would you like to get this into Dapper, or do you think there's a better way? I can make a pull request with a unit test, if you wish
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
Start in Dapper NET40/SqlMapper.cs around the mappings referenced in the issue and review how DateTime and nullable DateTime are represented. Check the existing mapping tests, then add the proposed unit test if the project supports the change. Done means DateTime2 mappings are covered and legacy datetime behavior remains working.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100