Base solution for your next web application
Open Closed

CreatorUserId is not set #2014


User avatar
0
soulmate created

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)
  • User Avatar
    0
    hikalkan created
    Support Team

    Are "SalesEntityBase" and "SalesFinancingEntityBase" or second one inherits the first one?

  • User Avatar
    0
    soulmate created

    Sorry my mistake. The name of the entity class is SalesEntityBase and Offer inherits from it. I corrected the original post.

  • User Avatar
    0
    hikalkan created
    Support Team

    Is it working for other entities? Say that is it saving current UserId to CreatorUserId when you create an Edition on UI?

  • User Avatar
    0
    soulmate created

    I created with /mpa a new edition and yes, the creatorid is saved

  • User Avatar
    0
    hikalkan created
    Support Team

    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;
    
  • User Avatar
    0
    soulmate created

    No, the entity is created from the UI. I am logged in as a "normal" user. Do you have any other ideas?

  • User Avatar
    0
    hikalkan created
    Support Team

    I mean that: have you entered tenancy name or did you left empty while logging in?

  • User Avatar
    0
    soulmate created

    ah sorry. I left it blank while logging in (the application has just a default tenant by now)

  • User Avatar
    0
    hikalkan created
    Support Team

    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.

  • User Avatar
    0
    soulmate created

    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?

  • User Avatar
    0
    hikalkan created
    Support Team

    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.