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

ToTable is not working #124

Closed Samuel-Rodrigues closed 1 year ago

Samuel-Rodrigues commented 4 years ago

Hello friends. I'm passing a value in ToTable ("UF"), but the fluent mapper always takes the name of the object "UfModel". Any tips? Thank you

public class UfModelMap : DommelEntityMap<UfModel> <-----
{
    public UfModelMap()
    {

        ToTable("UF");   <-------

        Map(uf => uf.ID).ToColumn("ID").IsKey().IsIdentity();
        Map(uf => uf.Descricao).ToColumn("DESCRICAO");
        Map(uf => uf.Ordem).ToColumn("ORDEM");
        Map(uf => uf.Sigla).ToColumn("SIGLA");
    }
}

public static class RegisterMappings
{
    public static void Register()
    {
        FluentMapper.Initialize(config =>
        {
            config.AddMap(new UfModelMap());
            config.ForDommel();
        });
    }
}
henkmollema commented 4 years ago
Samuel-Rodrigues commented 4 years ago
  • Você usa RegisterMappings.Register()é chamado na inicialização.
  • Quais versões de Dapper.FluentMap, Dommel e Dapper.FluentMap.Dommel você está usando?

verssions: Dapper.FluentMap 2.0.0, Dapper.FluentMap.Dommel 2.0.0, Dommel 2.1.0

I created this static class:

    public static class RegisterMappings
    {
        public static void Register()
        {
            FluentMapper.Initialize(config =>
            {
                config.AddMap(new UfModelMap());
                config.ForDommel();
            });
        }
    }

And I call on startup:

        public void ConfigureServices(IServiceCollection services)
        {
            RegisterMappings.Register();
...
Samuel-Rodrigues commented 4 years ago

@henkmollema I'm using the Dapper.FastCrud Is it incompatible?

My base repository:

using Dapper.FastCrud;
using Dommel;
using System.Collections.Generic;
using System.Data;
using System.Threading.Tasks;

namespace CadastroRegraPBM.Repositories.Impl
{
    public class DapperRepository<TEntity> where TEntity : class
    {
        protected readonly IUnitOfWork _unitOfWork;
        protected readonly IDbConnection _connection;

        public DapperRepository(IUnitOfWork unitOfWork)
        {
            _unitOfWork = unitOfWork;
            _connection = unitOfWork.Connection;

        }

        public DapperRepository(ICosmosRegraPBMConnectionFactory connectionFactory)
        {
            _connection = connectionFactory.CreateConnectionOpened();
        }

        public async Task<IEnumerable<TEntity>> FindAllAsync() =>
            await _connection.FindAsync<TEntity>();

        public async Task<TEntity> FindOneAsync(TEntity idEntity) =>
            await _connection.GetAsync(idEntity);

        public async Task InsertAsync(TEntity entity) =>
            await _connection.InsertAsync(entity, statement => statement
                .AttachToTransaction(_unitOfWork.Transaction)
            );

        public async Task UpdateAsync(TEntity entity) =>
            await _connection.UpdateAsync(entity, statement => statement
                .AttachToTransaction(_unitOfWork.Transaction)
            );
    }
}
henkmollema commented 1 year ago

I'm archiving this repository as I'm not using this library myself anymore and have no time maintaining it. Thanks for using it.