开发者

Automapper to map child list properties

Im trying to map a viewmodel to a domain that looks like the following:

domain

public class Category
{
     public int CategoryId {get; set;}
     public List<Product> Products {get; set;}
}

public class Product
{

    public int ProductId {get; set;}
    public int CategoryId {get; set;}
    public Category Category {get; set;}
}

viewModel

public class CategoryVM
{
     public int CategoryId {get; set;}
     public List<ProductVM> Products {get; set;}
}

public class ProductVM
{
    public int ProductId {get; set;}
}

Then this automapper code:

Mapper.CreateMap<CategoryVM, Category>();
Category category = Mapper.Map<CategoryVM, Category>(_category);

It throws the error on the Products property:

Trying to map WebUI.ViewModel.ProductVM to Domain.Product. Using mapping configuration for WebUI.ViewModel.ProductVM to Domain.Product Destination property: Products Missing type map configuration or unsupported mapping. Exception of type 'AutoMapper.AutoMapperMappingException' was thrown.

Im guessing I'm mapping child properties wrong or something? Any insight would be apprecia开发者_如何学运维ted.


You'll also need a map from ProductVM to Product

Automapping is finding these properties match but doesn't know how to map them and forth.


you need to create Custom Type Converters

Similar question: Problem auto mapping => collection of view models instead another view model

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜