Open Closed

Updating TenantId of AbpUser #5801


User avatar
0
ademaygun created
  • ABP Framework version: v7.3.2
  • UI Type: Angular
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace: The property or indexer 'IdentityUser.TenantId' cannot be used in this context because the set accessor is inaccessible.
  • Steps to reproduce the issue:

I want to update the tenantId of the user in the IdentityUser(AbpUser) table, but the TenantId setter is written as "protected." Is there a way for me to update the user's tenantId ?

var user = await userRepository.GetAsync(userId);
            user.TenantId = newTenantId; //compile error -> The property or indexer 'IdentityUser.TenantId' cannot be used in this context because the set accessor is inaccessible.


2 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team Fullstack Developer

    hi

            ObjectHelper.TrySetProperty(
                user,
                x => x.TenantId,
                () => tenantId
            );
    
    
  • User Avatar
    0
    ademaygun created

    Hi @maliming,

    The code you provided worked, thank you very much for your support

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19