我正在使用AutoMapper 6.1.1.0,并且具有以下类型:
来源:
public class PaymentPlan
{
private List<ScheduledPayment> _scheduledPayments = new List<ScheduledPayment>();
private Rates _ratesApplied;
public Rates RatesApplied
{
get { return _ratesApplied; }
set { _ratesApplied = value; }
}
public List<ScheduledPayment> ScheduledPayments
{
get { return _scheduledPayments; }
set { _scheduledPayments = value; }
}
}
目的地:
public class PaymentPlanModel
{
public RatesModel RatesApplied { get; set; }
public List<ScheduledPaymentModel> ScheduledPayments { get; set; }
}
public class ClassEnrollmentPaymentPlanVM : PaymentPlanModel
{
public Guid PricePlanID { get; set; }
public string Name { get; set; }
public bool IsSelected { get; set; }
public bool AutoDraftEnabled { get; set; }
public bool BillingDayChoiceEnabled { get; set; }
public List<int> AvailableBillingDays { get; set; }
public int SelectedBillingDay { get; set; }
}
映射配置文件:
CreateMap<Rates, RatesModel>();
CreateMap<ScheduledPayment, ScheduledPaymentModel>();
CreateMap<PaymentPlan, PaymentPlanModel>();
CreateMap<PaymentPlan, ClassEnrollmentPaymentPlanVM>();
//.IncludeBase<PaymentPlan, PaymentPlanModel>();
ClassEnrollmentPaymentPlanVM
继承了PaymentPlanModel
。我正在尝试从源PaymentPlan
映射到ClassEnrollmentPaymentPlanVM
以填充所有基本PaymentPlanModel
属性,但是它抱怨说这是“缺少类型映射配置或不支持的映射”。 Rates -> RatesModel
。在排除此错误的过程中,我尝试注释掉我的IncludeBase
通话,但得到的结果相同。我已经四倍检查了命名空间是否正确。为什么找不到我从Rates
到RatesModel
的映射?
编辑:
映射是这样启动的:
private static IMapper _mapper = MapperConfig.EntityWebMapper;
...
PaymentPlan paymentPlan = pmtCalc.CalculatePaymentPlan(calcInput);
ClassEnrollmentPaymentPlanVM paymentPlanVM = _mapper.Map<ClassEnrollmentPaymentPlanVM>(paymentPlan);
确切的异常/错误消息是AutoMapperMappingException
指出:
错误映射类型。
映射类型:PaymentPlan-> ClassEnrollmentPaymentPlanVM CRM.Logic.CRM.PaymentCalculation.PaymentPlan-> CRM.MVCWeb.ViewModels.Enrollment.ClassEnrollmentPaymentPlanVM
类型图配置:PaymentPlan-> ClassEnrollmentPaymentPlanVM CRM.Logic.CRM.PaymentCalculation.PaymentPlan-> CRM.MVCWeb.ViewModels.Enrollment.ClassEnrollmentPaymentPlanVM
属性:已应用费率
内部异常消息:
缺少类型映射配置或不支持的映射。
映射类型:费率-> RatesModel CRM.Logic.CRM.PaymentCalculation.Rates-> CRM.MVCWeb.Models.PaymentCalculation.RatesModel