Dapperがカスタム列からプロパティマッパーに対応するようになりました。これは、ITypeMapインターフェイスを介して行われます。A CustomPropertyTypeMapのクラスは、この作業のほとんどを行うことができますDapperのによって提供されます。例えば:
Dapper.SqlMapper.SetTypeMap(
    typeof(TModel),
    new CustomPropertyTypeMap(
        typeof(TModel),
        (type, columnName) =>
            type.GetProperties().FirstOrDefault(prop =>
                prop.GetCustomAttributes(false)
                    .OfType<ColumnAttribute>()
                    .Any(attr => attr.Name == columnName))));
そしてモデル:
public class TModel {
    [Column(Name="my_property")]
    public int MyProperty { get; set; }
}
これは、ことに注意することが重要ですCustomPropertyTypeMapの実装では、列名またはプロパティの属性が存在し、一致1がマップされないことが必要です。DefaultTypeMapのクラスは、標準機能を提供し、この動作を変更するために活用することができます。
public class FallbackTypeMapper : SqlMapper.ITypeMap
{
    private readonly IEnumerable<SqlMapper.ITypeMap> _mappers;
    public FallbackTypeMapper(IEnumerable<SqlMapper.ITypeMap> mappers)
    {
        _mappers = mappers;
    }
    public SqlMapper.IMemberMap GetMember(string columnName)
    {
        foreach (var mapper in _mappers)
        {
            try
            {
                var result = mapper.GetMember(columnName);
                if (result != null)
                {
                    return result;
                }
            }
            catch (NotImplementedException nix)
            {
            // the CustomPropertyTypeMap only supports a no-args
            // constructor and throws a not implemented exception.
            // to work around that, catch and ignore.
            }
        }
        return null;
    }
    // implement other interface methods similarly
    // required sometime after version 1.13 of dapper
    public ConstructorInfo FindExplicitConstructor()
    {
        return _mappers
            .Select(mapper => mapper.FindExplicitConstructor())
            .FirstOrDefault(result => result != null);
    }
}
そして、それが整ったら、属性が存在する場合に属性を自動的に使用し、それ以外の場合は標準の動作にフォールバックするカスタムタイプマッパーを簡単に作成できます。
public class ColumnAttributeTypeMapper<T> : FallbackTypeMapper
{
    public ColumnAttributeTypeMapper()
        : base(new SqlMapper.ITypeMap[]
            {
                new CustomPropertyTypeMap(
                   typeof(T),
                   (type, columnName) =>
                       type.GetProperties().FirstOrDefault(prop =>
                           prop.GetCustomAttributes(false)
                               .OfType<ColumnAttribute>()
                               .Any(attr => attr.Name == columnName)
                           )
                   ),
                new DefaultTypeMap(typeof(T))
            })
    {
    }
}
つまり、属性を使用したマップが必要なタイプを簡単にサポートできるようになりました。
Dapper.SqlMapper.SetTypeMap(
    typeof(MyModel),
    new ColumnAttributeTypeMapper<MyModel>());
ここに完全なソースコードの要点があります。