【发布时间】:2020-05-24 11:18:00
【问题描述】:
我正在使用 EF Core,并且两个表之间存在多对多关系。
public class Sale
{
public int Id { get; set; }
public DateTime Date { get; set; }
public double Total { get; set; }
public List<SalePaymentMethod> SalePaymentMethods { get; set; }
}
加入表:
public class SalePaymentMethod
{
public int DefferedPaymentCount { get; set; }
public int SaleId { get; set; }
public Sale Sale { get; set; }
public double Amount { get; set; }
public int PaymentMethodId { get; set; }
public PaymentMethod PaymentMethod { get; set; }
}
关系的另一个表:
public class PaymentMethod
{
public int Id { get; set; }
public string PaymentName { get; set; }
public bool PaymentType { get; set; }
public List<SalePaymentMethod> SalePaymentMethods { get; set; }
}
我可以使用 AutoMapper 获得如下扁平化的对象吗?
public class SaleUserBranchProductsDTO
{
public int Id { get; set; }
public DateTime Date { get; set; }
public double Total { get; set; }
public List<PaymentMethodDto> PaymentMethods { get; set; }
}
PaymentMethodDto 在哪里:
public class PaymentMethodDto
{
public string PaymentName { get; set; }
public bool PaymentType { get; set; }
public int DefferedPaymentCount { get; set; }
public double Amount { get; set; }
}
我的问题可能是我想在主映射中进行另一个映射。
【问题讨论】:
-
是的,这是可能的。你有没有尝试过?
-
@poke 我浪费了一整天的时间试图弄清楚如何解决它。发布这个问题几分钟后,我设法解决了它。谢谢:)
标签: asp.net-core entity-framework-core automapper-9