Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlMapper.TypeHandler not working #104

Open
mbtolou opened this issue Nov 15, 2021 · 2 comments
Open

SqlMapper.TypeHandler not working #104

mbtolou opened this issue Nov 15, 2021 · 2 comments

Comments

@mbtolou
Copy link

mbtolou commented Nov 15, 2021

Hi
cannot convert datetime to another type.

public class PersianDateTimeHandler : SqlMapper.TypeHandler<PersianDateTime>
  {
    public static readonly PersianDateTimeHandler Default = new PersianDateTimeHandler();

    public override void SetValue(IDbDataParameter parameter, PersianDateTime value)
    {
      parameter.Value = value.ToDateTime();
    }

    public override PersianDateTime Parse(object value)
    {
      return ((DateTime)value).ToPD();
    }
  }

      SqlMapper.AddTypeHandler(PersianDateTimeHandler.Default);

      SqlMapper.AddTypeMap(typeof(PersianDateTime), DbType.DateTime);
      SqlMapper.AddTypeMap(typeof(PersianDateTime?), DbType.DateTime);
      SqlMapper.AddTypeMap(typeof(PersianDateTime), DbType.DateTime2);
      SqlMapper.AddTypeMap(typeof(PersianDateTime?), DbType.DateTime2);
      SqlMapper.AddTypeMap(typeof(PersianDateTime), DbType.DateTimeOffset);
      SqlMapper.AddTypeMap(typeof(PersianDateTime?), DbType.DateTimeOffset);
@DarkWanderer
Copy link
Owner

This sounds more like a question to Dapper developers?

@mbtolou
Copy link
Author

mbtolou commented Nov 24, 2021

in your driver does not work .

in other driver like postgres work correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants