繁体   English   中英

自动映射器映射子列表属性

[英]Automapper to map child list properties

我试图将一个视图模型映射到如下所示的域:

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;}
}

然后此自动映射器代码:

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

它在Products属性上引发错误:

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.

我猜我在映射子属性错误或什么? 任何见识将不胜感激。

您还需要从ProductVM到产品的映射

自动映射发现这些属性匹配,但不知道如何来回映射它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM