Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Dto Inheritence #3284


User avatar
0
imad created

Hi,

How to achieve Dto inheritence in order for base and derived class map correctly to their correspondent Dto?

in the following example, i am always getting the ProductDto even if the product is a ProductA instance, how to make it map to ProductADto?

public class Product {}
public class ProductA : Product {}

[AutoMap(typeof(Product)]
public class ProductDto {}

[AutoMap(typeof(ProductA)]
public class ProductADto {}

public class GetProductForEditOutput
{
public Product EditProduct { get; set; }
}

1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You need to configure automapper like this <a class="postlink" href="https://github.com/AutoMapper/AutoMapper/wiki/Mapping-inheritance">https://github.com/AutoMapper/AutoMappe ... nheritance</a>.

    Thanks.