nop commerce automapper 异常,缺少类型映射配置或不受支持的映射
我试图调试并找到不匹配的来源,但我不能。关于去哪里看有什么想法吗?
这是模型
public class PatientModel : BaseNopEntityModel
{
public PatientModel()
{
AvailableStates = new List<SelectListItem>();
}
[NopResourceDisplayName("Patient.Fields.FirstName")]
[AllowHtml]
public string FirstName { get; set; }
[NopResourceDisplayName("Patient.Fields.LastName")]
[AllowHtml]
public string LastName { get; set; }
[NopResourceDisplayName("Patient.Fields.MiddleName")]
[AllowHtml]
public string MiddleName { get; set; }
[NopResourceDisplayName("Patient.Fields.RoomNumber")]
[AllowHtml]
public string RoomNumber { get; set; }
[NopResourceDisplayName("Patient.Fields.HospitalName")]
[AllowHtml]
public string HospitalName { get; set; }
[NopResourceDisplayName("Patient.Fields.StateProvince")]
public int? StateProvinceId { get; set; }
[NopResourceDisplayName("Patient.Fields.StateProvince")]
[AllowHtml]
public string StateProvince { get; set; }
[NopResourceDisplayName("Patient.Fields.City")]
[AllowHtml]
public string City { get; set; }
[NopResourceDisplayName("Patient.Fields.ZipPostalCode")]
[AllowHtml]
public string ZipPostalCode { get; set; }
public IList<SelectListItem> AvailableStates { get; set; }
public bool FirstNameDisabled { get; set; }
public bool LastNameDisabled { get; set; }
public bool MiddleNameDisabled { get; set; }
public bool RoomNumberDisabled { get; set; }
public bool HospitalNameDisabled { get; set; }
public bool StateProvinceDisabled { get; set; }
public bool CityDisabled { get; set; }
public bool ZipPostalCodeDisabled { get; set; }
}
,这是它尝试映射到的实体
public class Patient : BaseEntity, ICloneable
{
/// <summary>
/// Gets or sets the first name
/// </summary>
public virtual string FirstName { get; set; }
/// <summary>
/// Gets or sets the last name
/// </summary>
public virtual string LastName { get; set; }
/// <summary>
/// Gets or sets the middle name
/// </summary>
public virtual string MiddleName { get; set; }
/// <summary>
/// Gets or sets the patient room number
/// </summary>
public virtual string RoomNumber { get; set; }
public virtual string HospitalName { get; set; }
/// <summary>
/// Gets or sets the state/province identifier
/// </summary>
public virtual int? StateProvinceId { get; set; }
/// <summary>
/// Gets or sets the state/province
/// </summary>
public virtual StateProvince StateProvince { get; set; }
/// <summary>
/// Gets or sets the city
/// </summary>
public virtual string City { get; set; }
/// <summary>
/// Gets or sets the zip/postal code
/// </summary>
public virtual string ZipPostalCode { get; set; }
public virtual DateTime CreatedOnUtc { get; set; }
public object Clone()
{
var pat = new Patient()
{
FirstName = this.FirstName,
LastName = this.LastName,
MiddleName = this.MiddleName,
RoomNumber = this.RoomNumber,
HospitalName = this.HospitalName,
StateProvince = this.StateProvince,
StateProvinceId = this.StateProvinceId,
City = this.City,
ZipPostalCode = this.ZipPostalCode,
CreatedOnUtc = DateTime.UtcNow
};
return pat;
}
}
以及问题发生的映射器
public static PatientModel ToModel(this Patient entity)
{
return Mapper.Map<Patient, PatientModel>(entity);
}
I have tried to debug and find where the mismatch is coming from but I can not. Any ideas about where to look?
here is the model
public class PatientModel : BaseNopEntityModel
{
public PatientModel()
{
AvailableStates = new List<SelectListItem>();
}
[NopResourceDisplayName("Patient.Fields.FirstName")]
[AllowHtml]
public string FirstName { get; set; }
[NopResourceDisplayName("Patient.Fields.LastName")]
[AllowHtml]
public string LastName { get; set; }
[NopResourceDisplayName("Patient.Fields.MiddleName")]
[AllowHtml]
public string MiddleName { get; set; }
[NopResourceDisplayName("Patient.Fields.RoomNumber")]
[AllowHtml]
public string RoomNumber { get; set; }
[NopResourceDisplayName("Patient.Fields.HospitalName")]
[AllowHtml]
public string HospitalName { get; set; }
[NopResourceDisplayName("Patient.Fields.StateProvince")]
public int? StateProvinceId { get; set; }
[NopResourceDisplayName("Patient.Fields.StateProvince")]
[AllowHtml]
public string StateProvince { get; set; }
[NopResourceDisplayName("Patient.Fields.City")]
[AllowHtml]
public string City { get; set; }
[NopResourceDisplayName("Patient.Fields.ZipPostalCode")]
[AllowHtml]
public string ZipPostalCode { get; set; }
public IList<SelectListItem> AvailableStates { get; set; }
public bool FirstNameDisabled { get; set; }
public bool LastNameDisabled { get; set; }
public bool MiddleNameDisabled { get; set; }
public bool RoomNumberDisabled { get; set; }
public bool HospitalNameDisabled { get; set; }
public bool StateProvinceDisabled { get; set; }
public bool CityDisabled { get; set; }
public bool ZipPostalCodeDisabled { get; set; }
}
and here is the entity that it is trying to map to
public class Patient : BaseEntity, ICloneable
{
/// <summary>
/// Gets or sets the first name
/// </summary>
public virtual string FirstName { get; set; }
/// <summary>
/// Gets or sets the last name
/// </summary>
public virtual string LastName { get; set; }
/// <summary>
/// Gets or sets the middle name
/// </summary>
public virtual string MiddleName { get; set; }
/// <summary>
/// Gets or sets the patient room number
/// </summary>
public virtual string RoomNumber { get; set; }
public virtual string HospitalName { get; set; }
/// <summary>
/// Gets or sets the state/province identifier
/// </summary>
public virtual int? StateProvinceId { get; set; }
/// <summary>
/// Gets or sets the state/province
/// </summary>
public virtual StateProvince StateProvince { get; set; }
/// <summary>
/// Gets or sets the city
/// </summary>
public virtual string City { get; set; }
/// <summary>
/// Gets or sets the zip/postal code
/// </summary>
public virtual string ZipPostalCode { get; set; }
public virtual DateTime CreatedOnUtc { get; set; }
public object Clone()
{
var pat = new Patient()
{
FirstName = this.FirstName,
LastName = this.LastName,
MiddleName = this.MiddleName,
RoomNumber = this.RoomNumber,
HospitalName = this.HospitalName,
StateProvince = this.StateProvince,
StateProvinceId = this.StateProvinceId,
City = this.City,
ZipPostalCode = this.ZipPostalCode,
CreatedOnUtc = DateTime.UtcNow
};
return pat;
}
}
and mapper where the issue occurs
public static PatientModel ToModel(this Patient entity)
{
return Mapper.Map<Patient, PatientModel>(entity);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这意味着您从未为这两种类型调用
Mapper.CreateMap<>()
。That means you never called
Mapper.CreateMap<>()
for those two types.我找到了一种让它正常工作的方法,唯一的问题是我必须更改
和删除映射器并手动执行以将患者实体映射到模型。
I found a way of getting it to work correctly the only problem was I had to change
and remove the mapper and do it manually to map the patient entitiy to the model.