Open Closed

AutoMapper About Ignore Fields #7578


User avatar
0
kerem.kalemci created

Hi Everyone,

I have an issue about using automapper. I have two class named as ClassA and ClassB. ClassA has two field; Name,Surname . Also ClassB has three field; Name,Surname and Phone. When I want use automapper for ClassB => ClassA, I expect just fill Name and Surname in ClassA and work with successfully. But in this situation if I don't ignore the Phone field, I got error for non mapped fields. I just want map same fields. But my application is not start without ignore fields. Thanks from now.

  • ABP Framework version: v6.0.2
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can use Ignore method.

    for example:

    public class YourApplicationModuleAutoMapperProfile : Profile
    {
        public YourApplicationModuleAutoMapperProfile()
        {
            CreateMap<IdentitySession, IdentitySessionDto>()
                .ForMember(x => x.IpAddresses, s => s.MapFrom(x => x.GetIpAddresses()))
                .Ignore(x => x.TenantName) // ignore..
                .Ignore(x => x.UserName)
                .Ignore(x => x.IsCurrent);
        }
    }
    
    
Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13