【发布时间】:2019-08-02 10:42:09
【问题描述】:
我有两个模型,Receipt.cs 和 ReceiptProduct.cs。我想要实现的是从其父 Receipt 映射 ICollection ReceiptProducts 字段,如 PurchaseOrderId 和 ReceiptId。
Receipt.cs
public class Receipt
{
public Guid Id { get; set; }
public string Reference { get; set; }
public string PurchaseOrderId { get; set; }
public virtual ICollection<ReceiptProduct> ReceiptProducts { get; set; }
}
ReceiptProduct.cs
public class ReceiptProduct
{
public Guid Id { get; set; }
public string ReceiptId { get; set; }
public string PurchaseOrderId { get; set; }
public string ProductName { get; set; }
public string ProductId { get; set; }
public string Note { get; set; }
}
ReceiptProducts.ReceiptId
ReceiptProducts.PurchaseOrderId
我尝试了以下代码。但我得到了错误
CreateMap<DataEntities.Receipt, BusinessEntities.Receipt>()
.ForMember(dest => dest.ReceiptProducts.Select(x=>x.ReceiptId), automapper => automapper.MapFrom(src => src.Id));
错误: AutoMapper.AutoMapperConfigurationException: Custom configuration for members is only supported for top-level individual members on a type.
那么如何映射该集合属性值。
【问题讨论】:
标签: c# asp.net-core mapping automapper asp.net-core-2.0