Base solution for your next web application
Open Closed

SetCreationAuditProperties of AbpDbContext #174


User avatar
0
fengger created

increase the default field(TenantId,IsActive) protected virtual void SetCreationAuditProperties(DbEntityEntry entry) { if (entry.Entity is IHasCreationTime) { entry.Cast<IHasCreationTime>().Entity.CreationTime = Clock.Now; }

        if (entry.Entity is ICreationAudited)
        {
            entry.Cast&lt;ICreationAudited&gt;().Entity.CreatorUserId = AbpSession.UserId;
        }
       **if (entry.Entity is IMayHaveTenant)
        {
            entry.Cast&lt;IMayHaveTenant&gt;().Entity.TenantId = AbpSession.TenantId;
        }
        if (entry.Entity is IMustHaveTenant)
        {
            if (AbpSession.TenantId == null)
                throw new DbEntityValidationException("Configuration.MultiTenancy.IsEnabled is true,but TenantId is null");
            entry.Cast&lt;IMustHaveTenant&gt;().Entity.TenantId = AbpSession.TenantId.Value;
        }
        if (entry.Entity is IPassivable)
        {
            entry.Cast&lt;IPassivable&gt;().Entity.IsActive = true;
        }**
    }

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

    Hi,

    I could not understand to your purpose. Can you write some detail? You want to enhance SetCreationAuditProperties method. There are some codes in AbpDbContext may do similar job: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/master/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L184">https://github.com/aspnetboilerplate/as ... xt.cs#L184</a>

    Please create an issue about your idea with more detailed info: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/new">https://github.com/aspnetboilerplate/as ... issues/new</a>

    Thank you.