Исключение автомата nop commerce, отсутствует конфигурация карты типов или неподдерживаемое отображение - PullRequest
2 голосов
/ 13 октября 2011

Я попытался отладить и найти, откуда исходит несоответствие, но не могу.Есть идеи о том, где искать?

вот модель

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

Ответы [ 2 ]

3 голосов
/ 13 октября 2011

Это означает, что вы никогда не звонили Mapper.CreateMap<>() для этих двух типов.

0 голосов
/ 13 октября 2011

Я нашел способ заставить его работать правильно, единственная проблема состояла в том, что мне пришлось изменить

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

, удалить маппер и сделать это вручную, чтобы отобразить права пациента на модель.

...