henkmollema / Dapper-FluentMap

Provides a simple API to fluently map POCO properties to database columns when using Dapper.
MIT License
427 stars 86 forks source link

Doesn't seem to map for Dapper-1.50.5 / Dapper.Contrib-1.50.5 #78

Closed chriswolf-nrg closed 5 years ago

chriswolf-nrg commented 5 years ago

I have an entity which looks like:

[Dapper.Contrib.Extensions.Table("Correspondence")]
public class Correspondence : ICloneable
{
    public Correspondence()
    {
    }
    // other properties are name-for-name identical to db column names.
    [Column("bcc_archived_at")]
    public DateTime? BccArchivedAt { get; set; }
}

The database column is named "bcc_archived_at". I have a custom mapping class, like so:

Custom mapping class:

    internal class CorrespondenceMap : EntityMap<Correspondence>
    {
        internal CorrespondenceMap()
        {
            Map(c => c.BccArchivedAt).ToColumn("bcc_archived_at");
        }
    }

FluentMap initialization before any other code:

FluentMapper.Initialize(config =>
{
    config.AddMap<Correspondence>(new CorrespondenceMap());
});

Dapper.Contrib connection extension code for insert called like so:

using (var conn = ConnectionFactory.GetConnection(Dsn))
{
    Correspondence c = new Correspondence()
    {
        BccArchivedAt = DateTime.Now
    };
    long id = conn.Insert<Correspondence>(c);
}

This insert call throws:

System.Data.SqlClient.SqlException: 'Invalid column name 'BccArchivedAt'.'

Is FluentMap supposed to work with Dapper.Contrib extensions?

henkmollema commented 5 years ago

Is FluentMap supposed to work with Dapper.Contrib extensions?

Nope, it does not work with Dapper.Contrib. Shameless plug: it does work together with Dommel using the Dapper.FluentMap.Dommel integration component. However, Dommel might not provide the same feature set as Dapper.Contrib does. I suggest you try out the beta package.

dr-tariq-n-ahmad commented 4 years ago

Was this ever fixed in Dapper?