Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with class mapper #323

Open
leonardopottmayer opened this issue Aug 25, 2023 · 0 comments
Open

Problems with class mapper #323

leonardopottmayer opened this issue Aug 25, 2023 · 0 comments

Comments

@leonardopottmayer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant