DapperLib / DapperLib/Dapper

Different DateTimeKind per property or database

Open
#1,419 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature request
Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

When all DateTimes are stored using the same DateTimeKind, you can easily set the correct kind by using a DateTimeHandler : SqlMapper.TypeHandler<DateTime> and configuring that somewhere through the static SqlMapper.AddTypeHandler. This will then be applied for all mappings.

It would be useful if there were a way to configure this on a property-per-property basis, or at least per database connection.

One way to do this would be by passing more context to the TypeHandler's SetValue and Parse methods. Passing the name of the property would already help - we could then e.g. scan for a 'Utc'- or 'Local'-suffix. Better yet would be passing any attributes set to the property. This would be a very generic approach, not only usable for this use case.

Dapper could then include its own attribute for this, e.g. DateTimeKindAttribute, which is used by the default implementation of the DateTime TypeHandler.

Of course, this assumes it's possible to reflect on the property; and given Dapper's focus on speed, I'm not sure if that's feasible.

I'm using Dapper v2.0.30 and .NET Framework v4.2.6.

Related to #571 - but that issue isn't about supporting different DateTimekinds.

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 by reviewing SqlMapper.AddTypeHandler and the TypeHandler SetValue and Parse entry points mentioned in the issue. The work is complete when a defined, documented approach supports DateTimeKind configuration per property or database connection without losing Dapper's performance focus.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.