【问题标题】:nop commerce automapper exception, missing type map configuration or unsupported mappingnop commerce automapper 异常,缺少类型映射配置或不支持的映射
【发布时间】:2011-12-06 11:06:39
【问题描述】:

我试图调试并找到不匹配的来源,但我不能。关于在哪里看的任何想法?

这是模型

  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);
    } 

【问题讨论】:

  • 我找到了问题的答案,不得不手动将患者实体映射到模型

标签: asp.net-mvc-3 razor nopcommerce


【解决方案1】:

这意味着您从未为这两种类型调用过Mapper.CreateMap&lt;&gt;()

【讨论】:

    【解决方案2】:

    我找到了一种让它正常工作的方法,唯一的问题是我必须改变

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

    并移除映射器并手动将患者实体映射到模型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-01
      • 2017-04-16
      • 2015-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多