我有一个数据库实体,它存储这样的订单地址......
我有这样的 BLL 课程......
public class DeliveryAddress
{
public string Id { get; set; }
public string PersonyName { get; set; }
public string CompanyName { get; set; }
public List<string> AddressLines { get; set; }
public string Zip { get; set; }
public string City { get; set; }
public string CountryCode { get; set; }
}
还有这样的一堂课……
public class InvoiceAddress
{
public string Id { get; set; }
public string PersonyName { get; set; }
public string CompanyName { get; set; }
public List<string> AddressLines { get; set; }
public string Zip { get; set; }
public string City { get; set; }
public string CountryCode { get; set; }
}
我想根据 AddressType 列将 EF 实体映射到上述类。谁能解释我该怎么做?
更新
我想映射到OR.DeliveryAddress
addressType 是否为“Delivery”以及OR.InvoiceAddress
addressType 是否为“Invoice”
到目前为止,我已经能够做到这一点,但我不知道如何在实体映射级别应用条件......
Mapper.CreateMap<OrderAddress, OR.DeliveryAddress>()
.ForMember(d => d.City, o => o.MapFrom(s => s.city))
.ForMember(d => d.CompanyName, o => o.UseValue(string.Empty))
.ForMember(d => d.CountryCode, o => o.MapFrom(s => s.countryCode))
.ForMember(d => d.Id, o => o.MapFrom(s => s.id))
.ForMember(d => d.PersonyName, o => o.MapFrom(s => s.name))
.ForMember(d => d.Zip, o => o.MapFrom(s => s.zip));
更新 2
在与@Yuliam 讨论之后,这是我可以为我的问题提出的小提琴......