2

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

这是模型

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

2 回答 2

3

这意味着您从未调用Mapper.CreateMap<>()过这两种类型。

于 2011-10-12T20:27:21.673 回答
0

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

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

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

于 2011-10-13T12:17:35.750 回答