henkmollema / Dapper-FluentMap

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

Trouble with ToTable() method #90

Closed zadykian closed 4 years ago

zadykian commented 5 years ago

Hi, Henk! I've found that there are two interfaces with same names: Dapper.Dommel.FluentMapping.IDommelEntityMap Dapper.FluentMap.Dommel.Mapping.IDommelEntityMap It caused a problem when I tried to specify table name via ToTable("tableName") method:

public class DommelTableNameResolver : DommelMapper.ITableNameResolver
{
    public string ResolveTableName(Type type)
    {
        IEntityMap entityMap;
        if (FluentMapper.EntityMaps.TryGetValue(type, out entityMap))
        {
            IDommelEntityMap dommelEntityMap = entityMap as IDommelEntityMap;
            if (dommelEntityMap != null)
                return dommelEntityMap.TableName;
        }
        return DommelMapper.Resolvers.Default.TableNameResolver.ResolveTableName(type);
    }
}

Here is a save cast of client's DommelEntityMap to Dapper.FluentMap.Dommel.Mapping.IDommelEntityMap, but base class DommelEntityMap implements Dapper.Dommel.FluentMapping.IDommelEntityMap, so default table resolver is used in any case. I had to explicitly implement both DommelEntityMap and Dapper.FluentMap.Dommel.Mapping.IDommelEntityMap interface to deal with this problem. I use Dapper.Dommel 2.0.0.1 and Dapper.FluentMap.Dommel 1.7.0.

P.S. Thank you a lot for you work!

TroySchmidt commented 4 years ago

How did you resolve using this? I am having the same issue when trying to use version 2 of Dommel.

zadykian commented 4 years ago

How did you resolve using this? I am having the same issue when trying to use version 2 of Dommel.

As I said, I had to explicitly implement both DommelEntityMap and Dapper.FluentMap.Dommel.Mapping.IDommelEntityMap interfaces.

henkmollema commented 4 years ago

Dapper.Dommel is a different package (not mine). That's why those interfaces are incompatible.

Also, Dapper.FluentMap / Dapper.FluentMap.Dommel (which are mine) are not yet compatible with Dommel 2.0.

TroySchmidt commented 4 years ago

I upgraded Dapper.FluentMap.Dommel to be compatible and will be submitting a PR for it.

105