0
我有三個業務對象:AutoMapper繼承映射不工作
凡PayCaddyEntity
基本上只是提供了一個共同Id
財產,作爲一個「標誌」我可以在通用的限制使用。
public abstract class PayCaddyMessage : PayCaddyEntity
{
public string Subject { get; set; }
public ApplicationUser Sender { get; set; }
public ApplicationUser Receiver { get; set; }
public DateTime? TimeSent { get; set; }
public DateTime? TimeReceived { get; set; }
}
public class BetPaymentOffer: PayCaddyMessage
{
public string Description { get; set; }
public int Amount { get; set; }
public bool PaymentAccepted { get; set; }
}
我試圖將它們映射到一個共同的視圖模型如下:
Mapper.CreateMap<PayCaddyMessage, BetPaymentOfferViewModel>()
.Include<BetPaymentOffer, BetPaymentOfferViewModel>();
Mapper.CreateMap<BetPaymentOffer, BetPaymentOfferViewModel>();
和
var offer = new BetPaymentOffer { Sender = GetCurrentUser() };
var model = Mapper.Map<BetPaymentOfferViewModel>(offer);
基類屬性所導出的類設置不被映射。在model
中,Sender
爲空。我究竟做錯了什麼?