Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Framework throws error, still makes entry to db #1202


User avatar
0
antpstevens created

I want to create a user without using the tenant session(without even signing in and session). When I tried to make the entry to the User table and got the error message saying 'the username already taken'. That means a different tenant is using the same username.

That pretty much explains, I cannot create user with a username which exists in the table keeping the filter AbpDataFilters.MayHaveTenant turned off. So, I shoud keep it turned on, But when I try to create the user I get the error message 'Can not set TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MayHaveTenant filter is enabled'. The weird thing is, it still makes an entry to the database when the request is 'complete'.

Actually my requirement is to create some users under a particular tenant in a loop through a job. as soon as I create each user, I need to get the Id of the user to do some mapping to other tables. Since it makes the entry in the database only after the request cycle, I am not able to get the id of the user to execute my remaining business logic. I tried using 'CurrentUnitOfWork.SaveChanges();' but this method throws the error I explained above 'Can not set TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MayHaveTenant filter is enabled'. Please let me know what I should do.


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Which ABP version are you using? I assume the latest v0.9.1.1. In that case, I suggest you to use CurrentUnitOfWork.SetTenantId() (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants">http://www.aspnetboilerplate.com/Pages/ ... nd-tenants</a>) first to switch to desired tenant, then insert user to database (If ABP version is earlier, use SetFilterParameter method: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Data-Filters#DocSetFilterParams">http://www.aspnetboilerplate.com/Pages/ ... lterParams</a>). Also, "Can not set TenantId to a different value than the current filter parameter value or IAbpSession.TenantId while MayHaveTenant filter is enabled" control is removed in v0.9.1.1.

    But anyway it should not save entity normally, we should check it.

    Thanks.