Skip to content

Conversation

@pzavolinsky
Copy link

Given:

public class DateTimeOffsetHandler : SqlMapper.TypeHandler<DateTimeOffset>
{
  public override void SetValue(IDbDataParameter parameter, DateTimeOffset value)
  {
    ...
  }

  public override DateTimeOffset Parse(object value)
  {
    ...
  }
}

...

SqlMapper.AddTypeHandler(new DateTimeOffsetHandler());

In the original code:

  • When reading from the DB, Parse is called as expected.
  • When writing to the DB, SetValue is skipped because the subject of our TypeHandler (DateTimeOffset in this case) is included the typeMap and that short-circuits the type lookup.

By swapping the two checks we allow type handlers for standard .NET types which is useful to overcome driver limitations (such as MONO's System.Data.SqlClient DateTimeOffset support).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change v3.0 Changes awaiting the next breaking release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants