Skip to content

Problems with class mapper #323

@leonardopottmayer

Description

@leonardopottmayer

Hello. I'm having some trouble while trying to use ClassMapper...

My entity class:

public class Product : AuditableEntity
    {
        public Product() { }
        public Product(int id, string name, decimal price)
        {
            Id = id;
            Name = name;
            Price = price;
        }

        public int Id { get; set; }
        public string Name { get; set; }
        public decimal Price { get; set; }
    }

My mapper class:

public class ProductMapper : AuditableEntityClassMapper<Product>
    {
        public ProductMapper()
        {
            Table("product");

            Map(i => i.Id).Column("id").Key(KeyType.Identity);
            Map(i => i.Name).Column("name_desc");
            Map(i => i.Price).Column("price");
        }
    }

Additional class:

public abstract class AuditableEntityClassMapper<TEntity> : ClassMapper<TEntity> where TEntity : AuditableEntity
    {
        public AuditableEntityClassMapper()
        {
            Map(i => i.CreatedBy).Column("created_by");
            Map(i => i.CreatedAt).Column("created_at");
            Map(i => i.UpdatedBy).Column("updated_by");
            Map(i => i.UpdatedAt).Column("updated_at");
        }
    }

The stacktrace it generates:

MySqlConnector.MySqlException (0x80004005): Unknown column 'y_1.Name' in 'field list'
   at MySqlConnector.Core.ResultSet.ReadResultSetHeaderAsync(IOBehavior ioBehavior) in /_/src/MySqlConnector/Core/ResultSet.cs:line 43
   at MySqlConnector.MySqlDataReader.ActivateResultSet(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 130

It seems like it's ignoring the .Column() method in class mapper and it's generating the SQL sentence based on the class attributes. There's an example in stacktrace, with "Name" and "name_desc". But the same error happens with "CreatedAt" and "created_at", "UpdatedBy" and "updated_by", etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions