2011-10-12 62 views
2

我試圖調試並找到不匹配來自哪裏,但我不能。任何關於在哪裏看的想法?nop商業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); 
    } 
+0

我找到了問題的答案,並且必須手動將患者實體映射到模型 –

回答

3

這意味着你的實體從來沒有爲這兩種類型調用Mapper.CreateMap<>()

0

我發現得到它才能正常工作的唯一問題是,我不得不改變

public static PatientModel ToModel(this Patient entity) 
{ 
    return Mapper.Map<Patient, PatientModel>(entity); 
} 

,並刪除映射器和做手工繪製病人entitiy到模型的方式。

相關問題