Open Closed

Mapping extra properties to DTO does not work #2197


User avatar
0
nhontran created
  • ABP Framework version: v3.3.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

Hi, I have overridden the CreateAsync method in IdentityUserAppService, and added an extra property named "isActiveDirectory":

public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
{
    ...
    user.SetProperty(IsActiveDirectoryPropertyName, isActiveDirectory);
    ...
}

the extra property has been added successfully in db:

However, when we retrieve the mapping userDto, the ExtraProperties returned null

var userDto = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
user.MapExtraPropertiesTo(userDto);
return userDto;

Could you please help me check?

Thank you.


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://docs.abp.io/en/abp/latest/Object-Extensions#mapextrapropertiesto https://docs.abp.io/en/abp/latest/Object-Extensions#automapper-integration

  • User Avatar
    0
    nhontran created

    Hi maliming, I have implemented as the guide but it does not work.

    If you look at my post, I already called the MapExtraPropertiesTo method:

    user.MapExtraPropertiesTo(userDto);
    

    I also added the mapping in the Mapper Profile:

    CreateMap<IdentityUser, IdentityUserDto>().MapExtraProperties();
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to define a isActiveDirectory for IdentityUser

    https://docs.abp.io/en/abp/latest/Object-Extensions#object-extension-manager

  • User Avatar
    0
    nhontran created

    Hi @maliming, it works now.

    Thank you.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11