-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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.