Hello,
I have following abstract class that is derived from the AuditedEntity. From my understanding this should set the CreatorUserId for every new enity without setting it automatically.
public abstract class SalesEntityBase : AuditedEntity<int>, IFullAudited, IMustHaveTenant
{
public int TenantId { get; set; } = 1;
}
And following concrete one:
public class Offer : SalesEntityBase, IOffer
{
public int QutationId { get; set; }
}
I am calling:
var offer = new Offer();
offer.QutationId = 1;
//_offerRepository is default repository derived from IRepository
await _offerRepository.InsertOrUpdateAsync(offer);
However, CreatorUserId is not saved.
Do you have any idea why this is the case?
11 Answer(s)
-
0
Are "SalesEntityBase" and "SalesFinancingEntityBase" or second one inherits the first one?
-
0
Sorry my mistake. The name of the entity class is SalesEntityBase and Offer inherits from it. I corrected the original post.
-
0
Is it working for other entities? Say that is it saving current UserId to CreatorUserId when you create an Edition on UI?
-
0
I created with /mpa a new edition and yes, the creatorid is saved
-
0
Are you creating your entity from a host user? If so, it will not set CurrentUserId (this is by design). Also, you have this code which is not good and may lead to problems:
public int TenantId { get; set; } = 1;
-
0
No, the entity is created from the UI. I am logged in as a "normal" user. Do you have any other ideas?
-
0
I mean that: have you entered tenancy name or did you left empty while logging in?
-
0
ah sorry. I left it blank while logging in (the application has just a default tenant by now)
-
0
So, if you left it blank, then you are in host view (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#host-vs-tenant">http://www.aspnetboilerplate.com/Pages/ ... -vs-tenant</a>). Normally, a host user should not work with IMustHaveTenant entities.
-
0
ok, what is your recommendation? Remove the IMustHaveTenant from my base entity? Or would it be possible to assign a default tenant for the user?
-
0
My recommendation is that: You should not work with IMustHaveTenant entities from host users. They are for tenants. So, you should not allow to see that page in host view (if a host user see this page, he will see all data of all tenants which is not effective). You can create a permission with multiTenancySides = MultiTenancySides.Tenant, like we did for Dashboard page.
More info: ABP does not set a host user's id to CreatorUserId of a tenant entity, because the user and the entity may be in different databases and we get a foreign key exception in that case.