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)
-
0
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...
-
0
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.
-
0
Your configuration seems fine. Is the below line in your EF Core module ?
Configuration.EntityHistory.Selectors.Add("MyEntities", typeof(DocumentTemplateData));
-
0
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 ?
-
0
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.
-
0
Already done. I started with the same example on documentation. Nothing . No entity changes is tracked :(
-
0
is there any clue in logs?
-
0
@ivanosw1, could you send your project via email ? We can check it for you (to <a href="mailto:[email protected]">[email protected]</a>).
Thanks.
-
0
Yes sure. Project link sent by mail.
Thank you
-
0
Hi, some news about my question?
Thank you.