Search code examples
c#configurationaspnetboilerplate

Can't enable Entity History in ASP.NET Zero


I'm using ASP.NET Zero. Project Version: 5.1.0 and .NET Core 2.0 template. I'm trying to enable Entity History for my entity so that I can see the deleted and old column values for the table.

Entity class:

[Table("TestingEntity")]
[Audited]
public class TestingEntity : AuditedEntity , IMayHaveTenant
{
    public int? TenantId { get; set; }

    public virtual string Code { get; set; }
}

ApplicationModule class:

public class MyCompanyApplicationModule : AbpModule
{
    public override void PreInitialize()
    {
        // ...

        Configuration.EntityHistory.IsEnabledForAnonymousUsers = true;

        Configuration.EntityHistory.Selectors.Add(new NamedTypeSelector("Abp.AuditedEntities", type => typeof(IAudited).IsAssignableFrom(type)));
    }

    // ...
}

Running the following queries give no results.

SELECT * FROM [AbpEntityChangeSets]
SELECT * FROM [AbpEntityPropertyChanges]
SELECT * from [AbpEntityChanges]

Reference: https://aspnetboilerplate.com/Pages/Documents/Entity-History

Update

It is not giving proper results when I'm deleting an entity item.

It's inserting records for each property with old and new values the same in [AbpEntityPropertyChanges] table.

And there is no clear information that this entity item is deleted, its deletion time, and DeletedBy.

Is this due to using AuditedEntity in my entity class? I'm using hard delete, so I thought not to add these columns to the table: is deleted, its deletion time, and DeletedBy.


Solution

  • Entity History is disabled in ASP.NET Zero. You can enable it:

    Configuration.EntityHistory.IsEnabled = true;
    

    Update

    It is not giving proper results when I'm deleting an entity item.

    It's inserting records for each property with old and new values the same in [AbpEntityPropertyChanges] table.

    That has been resolved in PR #2977, which will be released with ABP v3.5.

    And there is no clear information that this entity item is deleted, its deletion time, and DeletedBy.

    Is this due to using AuditedEntity in my entity class? I'm using hard delete, so I thought not to add these columns to the table: is deleted, its deletion time, and DeletedBy.

    You won't find those in AbpEntityPropertyChanges table, since those aren't property changes.

    Additional information

    • relationship between AbpEntityChangeSets and AbpEntityChanges tables: EntityChange.cs

      public class EntityChange : Entity<long>, IMayHaveTenant
      {
          /// <summary>
          /// Gets/sets change set id, used to group entity changes.
          /// </summary>
          public virtual long EntityChangeSetId { get; set; }
      
          // ...
      }
      
    • possible values of EntityChange.ChangeType: EntityChangeType.cs

      public enum EntityChangeType : byte
      {
          Created = 0,
          Updated = 1,
          Deleted = 2
      }
      

    Do we have a plan to add UI for this feature? So that we can see Entity History from UI.

    This has been added in ASP.NET Zero 5.4.0.