Base solution for your next web application
Open Closed

Not able to implement Entity History in ABP Framework, Why? #4678


User avatar
0
manojreddy created

I'm using Project Version: 5.1.0 and .Net Core 2.0 framework. I'm trying to implement an Audit/History table for my Entity so that I can see the deleted and old column values for a 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()
    {
        //Adding authorization providers
        Configuration.Authorization.Providers.Add<AppAuthorizationProvider>();

        //Adding custom AutoMapper configuration
        Configuration.Modules.AbpAutoMapper().Configurators.Add(CustomDtoMapper.CreateMappings);

        Configuration.EntityHistory.IsEnabledForAnonymousUsers = true;

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

    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(typeof(MyCompanyApplicationModule).GetAssembly());
    }
}

Running following queries giving no results.

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

Referece: [https://aspnetboilerplate.com/Pages/Documents/Entity-History])

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

5 Answer(s)
  • User Avatar
    0
    alirizaadiyahsi created

    You pass parameter type => typeof(IAudited) but I can not see any entities that is type of IAudited entity. Could you change it with AuditedEntity ? I mean something like following:

    Configuration.EntityHistory.Selectors.Add(new NamedTypeSelector("Abp.AuditedEntities", type => typeof(AuditedEntity).IsAssignableFrom(type)));
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    manojreddy created

    Solved the issue, You can refer the below SO link.

    [https://stackoverflow.com/a/48768242/6527049])

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    aaron created
    Support Team
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    manojreddy created

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

    Its inserting records for each property with old and new value same in [AbpEntityPropertyChanges] table.

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

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

    EntityChangeId 3 is for deletion.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    alirizaadiyahsi created

    I think you got the answer here : <a class="postlink" href="https://stackoverflow.com/questions/48761496/cant-enable-entity-history-in-asp-net-zero">https://stackoverflow.com/questions/487 ... p-net-zero</a>

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)