DapperLib / DapperLib/Dapper

Mapping for DateTime2

Open
#229 7 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:typehandlers needs-investigation
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.