问题
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.
回答1:
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.
- information that this entity was deleted: EntityChange.ChangeType
- its deletion time: EntityChangeSet.CreationTime
- DeletedBy: EntityChangeSet.UserId
Additional information
relationship between
AbpEntityChangeSets
andAbpEntityChanges
tables: EntityChange.cspublic 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.cspublic 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.
回答2:
I have solved the issue by doing the below change in file ProjectName.EntityFrameworkCore\EntityFrameworkCore\ProjectNameEntityFrameworkCoreModule.cs by setting the following value to true
, You need to enable Entity History.
Configuration.EntityHistory.IsEnabled = true;
You can refer https://github.com/aspnetzero/aspnet-zero-core/issues/818#issuecomment-365250173.
来源:https://stackoverflow.com/questions/48761496/cant-enable-entity-history-in-asp-net-zero