Entity framework core 映射派生类型的抽象类
我有以下抽象类及其实现:Entity framework core 映射派生类型的抽象类,entity-framework-core,automapper,Entity Framework Core,Automapper,我有以下抽象类及其实现: public abstract class TransactionResult : AuditableEntity { public int Id { get; set; } [Required, MaxLength(25)] public string Status { get; set; } [Required, MaxLength(50)] public string ReferenceId { get; set; }
public abstract class TransactionResult : AuditableEntity
{
public int Id { get; set; }
[Required, MaxLength(25)]
public string Status { get; set; }
[Required, MaxLength(50)]
public string ReferenceId { get; set; }
public string ResultMetaData { get; set; }
[Required, MaxLength(10)]
public string CardType { get; set; }
[Required, MaxLength(10)]
public string CardDescription { get; set; }
public int? CustomerSavedCardId { get; set; }
public CustomerSavedCard CustomerSavedCard { get; set; }
public int? PaymentPlanDetailId { get; set; }
public PaymentPlanDetail PaymentPlanDetail { get; set; }
public int? CustomerMembershipBillingId { get; set; }
public CustomerMembershipBilling CustomerMembershipBilling { get; set; }
public Guid? NotificationId { get; set; }
public Notification Notification { get; set; }
[Required, MaxLength(25)]
public string Source { get; set; }
public string CustomerKey { get; set; }
public Customer Customer { get; set; }
public int Amount { get; set; }
}
public class Approve : TransactionResult
{
}
public class Decline : TransactionResult
{
public string Reason { get; set; }
}
我在使用自动映射器时试图找到原因
profile.CreateMap<Entities.TransactionResult, TransactionsDto>()
.ForMember(dest => dest.CustomerName, opt => opt.MapFrom(src => src.Customer.FirstName + " " + src.Customer.LastName))
.ForMember(dest => dest.NotificationId, opt => opt.MapFrom(src => src.NotificationId))
.ForMember(dest => dest.Reason, opt => opt.MapFrom(src => src.GetType() == typeof(Entities.Decline) ? ((Entities.Decline)src).Reason : null))
profile.CreateMap()
.FormMember(dest=>dest.CustomerName,opt=>opt.MapFrom(src=>src.Customer.FirstName+“”+src.Customer.LastName))
.FormMember(dest=>dest.NotificationId,opt=>opt.MapFrom(src=>src.NotificationId))
.FormMember(dest=>dest.Reason,opt=>opt.MapFrom(src=>src.GetType()==typeof(Entities.defect)?((Entities.defect)src)。原因:null)
我在向事务结果中添加拒绝转换时出错
客户端投影包含对“System.RuntimeType”常量表达式的引用。这可能会导致内存泄漏;考虑将此常量赋值给局部变量,并使用查询中的变量。有关更多信息,请参阅
自动映射支持继承 删除属性
原因
的行,并为拒绝
创建特定配置文件,如下所示:
profile.CreateMap<Entities.Decline, TransactionsDto>()
.IncludeBase<Entities.TransactionResult, TransactionsDto>();
profile.CreateMap()
.IncludeBase();