【发布时间】:2022-08-14 10:23:40
【问题描述】:
我正在尝试使用 AutoMapper 将 DTO 映射到 Entity 类,但我不断收到错误消息。这是 DTO 类
public class Product
{
public string ID { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public PriceTiers PriceTiers { get; set; }
}
这是实体
public partial class Product
{
public Product()
{
PriceTiers = new List<PriceTiers>();
}
[Key]
public string ID { get; set; }
public string SKU { get; set; }
public string Name { get; set; }
public virtual ICollection<PriceTiers> PriceTiers { get; set; }
}
为什么我不断收到以下错误
{\"Missing type map configuration or unsupported mapping.\\r\\n\\r\\nMapping types:\\r\\nPriceTiers -> ICollection`1\\r\\nWeb.Areas.DEAR.DTOs.PriceTiers ->
System.Collections.Generic.ICollection`1[[Web.Areas.DEAR.Data.PriceTiers, Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]\\r\\n\\r\\n
Destination Member:\\r\\nPriceTiers\\r\\n\"}
这就是我在 Profile 类中的内容
AllowNullCollections = true;
CreateMap<DTOs.Product, Data.Product>();
CreateMap<DTOs.PriceTiers, Data.PriceTiers>();
这就是我用来映射类的
var products = _mapper.Map<IEnumerable<Product>>(result.Products);
这就是 program.cs 中的内容
builder.Services.AddAutoMapper(typeof(AutoMapperProfiles).Assembly);
标签: asp.net .net automapper