Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How configure Entity History on Abp Core & Angular 5.5.2 #5484


User avatar
0
ivanosw1 created

Hi, I've been trying since this afternoon to configure Entity History but changes are not tracked. What I'm missing? This is what I've done on my module (loaded as plugin)

On PreInitialize

Configuration.EntityHistory.IsEnabled = true; 
  Configuration.EntityHistory.Selectors.Add("MyEntities", typeof(DocumentTemplateData));

DocumentTemplateData

[Audited]
    public class DocumentoTemplateData : FullAuditedEntity, IPassivable
    {
              
        public string Name { get; set; }
        public string Description { get; set; }
        public string Html { get; set; }
        ....

On ApplicationService on Web side:

[HttpPut("UpdateDocument")]
        [UseCase(Description = "Update document")]
        public async Task UpdateDocument(UpdateDocumentDto input)
        {
            await _reportEngineApplicationService.UpdateDocument(input);
        }

On ReportEngineApplicationService in interal side:

[DisableAuditing]  // <-  Do not show these methods on logs
    public class ReportEngineApplicationService : ApplicationService, IReportEngineApplicationService
    {
        private readonly IReportEngine _reportEngine;
        private readonly IDocumentTemplateRepository _documentTemplateRepository;
       ...

public async Task UpdateDocument(UpdateDocumentDto input)
        {
            var document = await _documentTemplateRepository.GetAsync(input.Id);
   // some business stuff
          await _documentTemplateRepository.UpdateAsync(document);

Repository

public async Task UpdateAsync(DocumentTemplate aggregate)
        {

            var data = aggregate.Snapshot;
            data.Name = aggregate.Name;
            data.Description = aggregate.Description;
            data.Html = aggregate.Html;
            data.IsActive = aggregate.IsActive;
            await _documentTemplateRepository.UpdateAsync(data);

Thank you


11 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    That's because you have [DisableAuditing] attribute on ReportEngineApplicationService Remove that attribute and try again.

    <ins>Notes</ins>

    • DisableAuditing takes priority over the Audited attribute.
    • A property must be public in order to be saved in the change logs. Private and protected properties are ignored.
    • Entity History only works for entities.
    • Entity History only works for scalar properties, e.g. string, int, bool...
  • User Avatar
    0
    ivanosw1 created

    Thank you @alper.

    I've tried without [DisableAuditing] but nothing happens on entity history. Only my table is updated.

    Other suggestions ? Do you see something wrong on my code? Since I haven't errors, I guess is a configuration problems.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Your configuration seems fine. Is the below line in your EF Core module ?

    Configuration.EntityHistory.Selectors.Add("MyEntities", typeof(DocumentTemplateData));
    
  • User Avatar
    0
    ivanosw1 created

    I've tried in PreInitilize method of all modules. Application, Core, Repository and Web

    The entity DocumentTemplateData is defined in Core and used in Repository.

    Exists some sample project ?

  • User Avatar
    0
    alper created
    Support Team

    so to understand the issue, let's remove the below code;

    Configuration.EntityHistory.Selectors.Add("MyEntities", typeof(DocumentTemplateData));
    

    and add this selector in your module's PreInitialize method.

    Configuration.EntityHistory.Selectors.Add(
        new NamedTypeSelector(
            "Abp.FullAuditedEntities",
            type => typeof (IFullAudited).IsAssignableFrom(type)
        )
    );
    

    it will capture all the full audit entities.

  • User Avatar
    0
    ivanosw1 created

    Already done. I started with the same example on documentation. Nothing . No entity changes is tracked :(

  • User Avatar
    0
    alper created
    Support Team

    is there any clue in logs?

  • User Avatar
    0
    ivanosw1 created

    No, nothing relevant on log. I've attached an extract of logs.txt

    Note: the real name of the method is "AggiornaDocumento" and not UpdateDocument.

    Thank you Logs.zip

  • User Avatar
    0
    ismcagdas created
    Support Team

    @ivanosw1, could you send your project via email ? We can check it for you (to <a href="mailto:[email protected]">[email protected]</a>).

    Thanks.

  • User Avatar
    0
    ivanosw1 created

    Yes sure. Project link sent by mail.

    Thank you

  • User Avatar
    0
    ivanosw1 created

    Hi, some news about my question?

    Thank you.