Dapper-FluentMap icon indicating copy to clipboard operation
Dapper-FluentMap copied to clipboard

ToTable is not working

Open Samuel-Rodrigues opened this issue 4 years ago • 3 comments

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();
        });
    }
}

Samuel-Rodrigues avatar Sep 22 '20 15:09 Samuel-Rodrigues

  • Are you use RegisterMappings.Register() is called at startup.
  • Which versions of Dapper.FluentMap, Dommel and Dapper.FluentMap.Dommel are you using?

henkmollema avatar Sep 22 '20 18:09 henkmollema

  • 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 avatar Sep 22 '20 18:09 Samuel-Rodrigues

@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)
            );
    }
}

Samuel-Rodrigues avatar Sep 22 '20 18:09 Samuel-Rodrigues

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

henkmollema avatar Apr 19 '23 13:04 henkmollema