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

Invalid column name mapping properties of base class #103

Closed DiegoHSeto closed 4 years ago

DiegoHSeto commented 4 years ago

I'm working with inheritance, but, when i map properties of a base class, i'm getting the error: "Invalid column name ". I'm using the forDommel() line code too.

henkmollema commented 4 years ago

I'm moving this issue to Dapper.FluentMap.

Also, do you have a reproducible code sample for this?

BelvedereHenrique commented 3 years ago

Do we have a fix on this? I'm facing the same issue.

BelvedereHenrique commented 3 years ago

My base class

    public class EntityBase
    {
        public int Id { get; set; }
        public bool Status { get; set; }
    }

My entity

    public class Avaliacao : EntityBase
    {
        public string Designacao { get; set; }
    }

Mapping:

    public class AvaliacaoMap : DommelEntityMap<Avaliacao>
    {
        public AvaliacaoMap()
        {
            ToTable("T_AQV_AVALIACAO");
            Map(a => a.Id).ToColumn("PK_AVL").IsKey().IsIdentity();
            Map(a => a.Designacao).ToColumn("DESIG_AVL");
            Map(a => a.Status).ToColumn("STATUS_AVL");
        }
    }

FluentMap setup:

            FluentMapper.Initialize(config =>
            {
                config.AddMap(new AvaliacaoMap());
                config.AddMap(new CondicaoAcessoMap());
                config.AddMap(new CondicaoReproducaoMap());
                config.AddMap(new DepositoMap());

                config.ForDommel();
            });

The query:

            var result = await Connection
                .SelectAsync<Avaliacao>(a=> a.Designacao.Contains(designacao) && a.Status == status);

The error: System.Data.SqlClient.SqlException (0x80131904): Nome de coluna 'Status' inválido. (invalid Status column)