nop commerce automapper 异常,缺少类型映射配置或不受支持的映射

发布于 2024-12-09 19:19:27 字数 3800 浏览 0 评论 0原文

我试图调试并找到不匹配的来源,但我不能。关于去哪里看有什么想法吗?

这是模型

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瘫痪情歌 2024-12-16 19:19:27

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

That means you never called Mapper.CreateMap<>() for those two types.

尛丟丟 2024-12-16 19:19:27

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

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

和删除映射器并手动执行以将患者实体映射到模型。

I found a way of getting it to work correctly the only problem was I had to change

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

and remove the mapper and do it manually to map the patient entitiy to the model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文