无法在 ASP.NET 零中启用实体历史记录

Can't enable Entity History in ASP.NET Zero

我正在使用 ASP.NET 零。项目版本:5.1.0 和 .NET Core 2.0 模板。我正在尝试为我的实体启用实体历史记录,以便我可以看到 table.

的已删除列值和旧列值

实体class:

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

    public virtual string Code { get; set; }
}

应用模块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)));
    }

    // ...
}

运行 以下查询没有结果。

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

参考: https://aspnetboilerplate.com/Pages/Documents/Entity-History

更新

当我删除实体项目时,它没有给出正确的结果。

它正在为每个 属性 插入记录,在 [AbpEntityPropertyChanges] table.

中新旧值相同

并且没有明确的信息表明该实体项被删除,删除时间,删除人。

这是因为在我的实体 class 中使用了 AuditedEntity 吗?我正在使用硬删除,所以我认为不要将这些列添加到 table:已删除、删除时间和 DeletedBy。

我通过在文件 ProjectName.EntityFrameworkCore\EntityFrameworkCore\ProjectNameEntityFrameworkCoreModule.cs 中进行以下更改解决了这个问题,方法是将以下值设置为 true,您需要启用实体历史。

Configuration.EntityHistory.IsEnabled = true;

可以参考https://github.com/aspnetzero/aspnet-zero-core/issues/818#issuecomment-365250173.

实体历史在 ASP.NET 零中被禁用。您可以启用它:

Configuration.EntityHistory.IsEnabled = true;

更新

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.

已在 PR #2977 中解决,它将与 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.

您不会在 AbpEntityPropertyChanges table 中找到它们,因为它们不是 属性 更改。

附加信息

  • AbpEntityChangeSetsAbpEntityChangestable之间的关系: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; }
    
        // ...
    }
    
  • 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.

这已添加到 ASP.NET 零 5.4.0