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

Mapping problem with subclass

Open melody-dev opened this issue 5 years ago • 1 comments

Sample for this case

First is super class like below

public class User
{
    public string UserId { get; set; }
    public string Email { get; set; }
}

Second is subclass like below

public class AdminUser : User
{
    public int Role { get; set; }
}

Than i create mapper and initial mapper

public class UserMap : EntityMap<User>
{
    public UserMap()
    {
        Map(c => c.UserId).ToColumn("user_id");
    }
}

FluentMapper.Initialize(config =>
{
    config.AddMap(new UserMap());
}

Everything work as properly when i set return type is User in query

But when i try to change return type from User to AdminUser in the same query it look like mapping doesn't work, UserId become null.

Is any some extra work for this solution ?

melody-dev avatar Dec 20 '19 09:12 melody-dev

You'll need to create a mapping for AdminUser as well.

henkmollema avatar Jul 24 '20 08:07 henkmollema

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