AutoMapper 问题 - 无法忽略 属性

AutoMapper issue - cannot get ignore property

我正在挠头试图让自动映射器忽略一个属性,希望有人能告诉我我在做一些愚蠢的事情!

领域模型

public class RamsDocument
{
  // properties...

}

public class Contract
{
  // properties...
  Public IColleciton<RamsDocument> RamsDocuments {get; set;}

}

查看模特

public class RamsList
{
  // properties...

}

public class Contract
{
  // properties...
  Public IList<RamsList> RamsDocuments {get; set;}

}

我已经尝试了所有组合来让它忽略 RamsDocuments 属性,因为您可以看到它们是不同的类型。

Mapper.CreateMap<Domain.Models.Contract, ViewModels.Contract>()
                .ReverseMap()
                .ForMember(ignore => igonre.RamsDocuments, opt => opt.Ignore())
                .ForSourceMember(ignore => igonre.RamsDocuments, opt => opt.Ignore());

我有一个解决方法,就是将视图模型上的 属性 重命名为 RamsList 而不是 RamsDocuments,这样效果很好。

如果我将两个属性都命名为 RamsDocuments,则在尝试映射时会出现以下错误

AutoMapperMappingException: Missing type map configuration or unsupported mapping.

Mapping types: RamsDocuments -> RamsList CenelecSiteInspector.Domain.Models.RamsDocuments -> CenelecSiteInspector.WebPresentation.ViewModels.RamsList

Destination path: Contract.Site.Site.Contracts.Contracts.Contracts0[0].RamsDocuments0[0].RamsDocuments0[0].RamsDocuments0[0]

Source value: System.Data.Entity.DynamicProxies.RamsDocuments_B721359E9A40092B947528944166EA0B12FD5C0B9E9FFD19D91C8409CF04133E

尝试将忽略放在反向映射之前,因为您正在单向忽略属性。