I'm trying to map my DTO class to the native one. Here are the classes:
public class CategoryResource
{
public int Id { get; set; }
public string Code { get; set; }
public string Description { get; set; }
}
public class Category
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Code { get; set; }
[StringLength(255)]
public string Description { get; set; }
public ICollection<CategoryToProduct> Products { get; set; }
public Category()
{
Products = new Collection<CategoryToProduct>();
}
}
and the usage
var category = mapper.Map<CategoryResource, Category>(categoryResource);
As above code throws an error of this kind:
Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the constructor parameters =========================================================================== CategoryResource -> Category (Destination member list)
Unmapped properties: Products
I changed my mapping profile to:
CreateMap<CategoryResource, Category>()
.ForMember(x=>x.Products, opt => opt.Ignore());
But still, I have the same error. Could you please advice me what I do wrong here? I already restarted the IIS and AutoMapper version is 6.2.2
To answer question from comments, that's the whole MappingProfile
public class MappingProfile : Profile
{
public MappingProfile()
{
//Domain to API
CreateMap<Type, TypeResource>();
CreateMap<Unit, UnitResource>();
CreateMap<Category, CategoryResource>();
//API to domain
CreateMap<TypeResource, Type>();
CreateMap<UnitResource, Unit>();
CreateMap<CategoryResource, Category>()
.ForMember(x=>x.Products, opt => opt.Ignore());
}
}