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

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.0.0-preview. Updated on September 18, 2025, 07:10