简体   繁体   English

自动映射器:具有相同名称的类和属性未映射

[英]Automapper: Class and property with identical names not mapping

Below is a barebones class setup for what I'm describing. 以下是我所描述的准系统类设置。

public class List
{
   public int Id {get;set;}
   public RecipientCount RecipientCount {get;set;}
   public RecipientCount SomeOtherName {get;set;}
}

public class RecipientCount
{
   public int Total {get;set;}
   public int Active {get;set;}
}

public class ListDto
{
   public int id {get;set;}
   public RecipientCountDto recipientCount {get;set;}
   public RecipientCountDto someOtherName {get;set;}
}

public class RecipientCountDto
{
   public int total {get;set;}
   public int active {get;set;}
}

public class AutoMapperConfiguration
{
    public void Init(AutoMapper.IConfiguration config)
    {
       config.CreateMap<RecipientCount,RecipientCountDto>();
    }
}

if I attempt to use this it throws a: 如果我尝试使用它,它会抛出:

   The following property on Reachmail.Domain.Component.RecipientCountDto cannot 
   be mapped: 
   recipientCount
   Add a custom mapping expression, ignore, add a custom resolver, or modify the 
   destination type Reachmail.Domain.Component.RecipientCount.
   Context:
   Mapping to property recipientCount of type Reachmail.Domain.Component.RecipientCountDto 
   from source type Reachmail.Domain.Component.RecipientCount
   Mapping to type Reachmail.Web.UI.Controllers.ListDto from source type 
   Reachmail.Domain.Contacts.Lists.List
   Exception of type 'AutoMapper.AutoMapperConfigurationException' was thrown.

If however I remove RecipientProviderDto.recipientProvider it works fine. 但是,如果我删除了RecipientProviderDto.recipientProvider,它可以正常工作。 So it leads me to believe that its the fact that the class name and the property are the same that is causing an issue. 因此,这使我相信类名称和属性相同的事实导致了问题。 Any insights on how to fix it or if its a bug? 关于如何修复或是否存在错误的任何见解?

try with UpperLetter: 尝试使用UpperLetter:

public class ListDto
{
   public int Id {get;set;}
   public RecipientCountDto RecipientCount {get;set;}
   public RecipientCountDto SomeOtherName {get;set;}
}

public class RecipientCountDto
{
   public int Total {get;set;}
   public int Active {get;set;}
}

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM