AutoMapperMappingException:缺少类型映射配置或不支持的映射

我第一次尝试使用AutoMapper。 GSMSite映射正常,但是尝试映射GSMUnit时出现错误:

  

AutoMapperMappingException:缺少类型映射配置或不支持的映射。

我需要指定GSMSite和GSMUnit之间的关系吗?

域类:

public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Company { get; set; }    
    public string Telephone { get; set; } 
    public bool PasswordReset { get; set; } = false;
    public virtual ICollection<GSMSite> GSMSites { get; set; }
}

public class GSMSite
{
    public int Id { get; set; }
    public string SiteName { get; set; }
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string Town { get; set; }
    public string Postcode { get; set; }
    public string ContactName { get; set; }
    public string ContactNumber { get; set; }
    public string ContactEmail { get; set; }
    public string ApplicationUserId { get; set; }
    public virtual ApplicationUser ApplicationUser { get; set; }
    public virtual ICollection<GSMUnit> GSMUnits { get; set; }
}

public class GSMUnit
{
    public int Id { get; set; }
    public string Model { get; set; }
    public string Firmware { get; set; }
    public string TelephoneNum { get; set; }
    public int GSMSiteId { get; set; }
    public virtual GSMSite GSMSite { get; set; }
}

合同类:

public class GSMResponse
{
     public int Id { get; set; }
     public string Model { get; set; }
     public string Firmware { get; set; }
     public string TelephoneNum { get; set; }
}

public class SiteResponse
 {
    public int Id { get; set; }
    public string SiteName { get; set; }
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string Town { get; set; }
    public string Postcode { get; set; }
    public string ContactName { get; set; }
    public string ContactNumber { get; set; }
    public string ContactEmail { get; set; }

}

映射:

public DomainToResponseProfile()
{
        CreateMap<GSMSite,SiteResponse>();
        CreateMap<GSMUnit,GSMResponse>();           
}    
riijlcvyp 回答:AutoMapperMappingException:缺少类型映射配置或不支持的映射

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3101076.html

大家都在问