自动映射器-映射到列表现有实体时不能忽略属性

时间:2018-06-26 06:43:31

标签: c# automapper automapper-6

我有两个TenantRestrictSourceEntityTenantRestrictSource和映射器个人资料

CreateMap<TenantRestrictSourceEntity, TenantRestrictSource>()
         .ForMember(dest => dest.Tenant, opt => opt.Ignore());

public class TenantRestrictSourceEntity
{
    public string SourceType { get; set; }
    public bool? Enable { get; set; }
    public int TenantId { get; set; }
}

public sealed class TenantRestrictSource
{
    public int Id { get; set; }
    public string SourceType { get; set; }
    public bool Enable { get; set; }
    public int TenantId { get; set; }
    public Tenant Tenant { get; set; }
}

当我使用TenantRestrictSourceEntity将一个TenantRestrictSource映射到一个Mapper.Map(tenantRestrictSourceEntity, tenantRestrictSource)时。一切正常。租户属性被正确忽略。

但是当我尝试将列表TenantRestrictSourceEntity映射到具有TenantRestrictSource的列表Mapper.Map(tenantRestrictSourceEntities, tenantRestrictSources)时,承租人属性始终为null

映射列表对象时如何忽略该属性?

0 个答案:

没有答案