I have the source and destination objects like this:
class ProductWithCategories // Source class
{
public Product Product { get; set; } // Product is an EF entity class
public IEnumerable<Category> Categories { get; set; }
}
class ProductViewModel // Dest class
{
public int Id { get; set; }
// Other properties with the same name as Product class
public IEnumerable<CategoryViewModel> Categories { get; set; }
}
So, my need is to map the values of source.Product
into dest
, and then source.Categories
into dest.Categories
. Is it possible with AutoMapper?
I have tried this and I was not surprised when it failed:
config.CreateMap<ProductWithCategories, ProductViewModel>()
.ForMember(q => q, option => option.MapFrom(q => q.Product))
.ForMember(q => q.Categories, option => option.MapFrom(q => q.Categories));
Here is the exception I received:
[AutoMapperConfigurationException: Custom configuration for members is only supported for top-level individual members on a type.]
Mapper
. – Becki