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)
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    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);
        }
    }
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.