question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Audit.EntityFramework: Old and new value are always the same

See original GitHub issue

Hi!

I´m using Audit.EntityFramework and on log output the old and new values for changed entity are always the same!

My config on statup.cs:

Audit.Core.Configuration.Setup().UseSqlServer(c => {
                c.ConnectionString(Configuration.GetConnectionString("audit.db"));
                c.Schema("dbo");
                c.TableName("Event");
                c.IdColumnName("EventId");
                c.JsonColumnName("Data");
                c.LastUpdatedColumnName("LastUpdatedDate");
                
            });

            Audit.EntityFramework.Configuration.Setup()
                .ForAnyContext(x => x.IncludeEntityObjects(true)
                                     .AuditEventType("{context}:{database}"))
                .UseOptOut();

Thankyou for the library and support!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
thepirat000commented, Feb 28, 2019

I don’t think this is related to this library, you could reuse that code just by adding a method on your DbContext like:

public int AttachUpdateEntity(object entityToUpdate)
{
    var entry = this.Attach(entityToUpdate); // Attach to the DbContext
    var updated = entry.CurrentValues.Clone();
    entry.Reload();
    entry.CurrentValues.SetValues(updated);
    entry.State = EntityState.Modified;
    return this.SaveChanges();
}

1reaction
thepirat000commented, Aug 5, 2023

The configuration in applicable by DbContext, not by controller. You can do enable it globally (for any context) with the following code in your startup:

Audit.EntityFramework.Configuration.Setup()
    .ForAnyContext(config => config
        .ReloadDatabaseValues(true));
Read more comments on GitHub >

github_iconTop Results From Across the Web

EF2.2 Core 2.2 Auditing returns same old and new value ...
I am trying to implement an Audit table in my .net core (2.2) using EF 2.2 code first. My intention is to log...
Read more >
Audit Trail Implementation in ASP.NET Core with Entity ...
We will track the following with our implementation. TableName; Affected Column(s); Primary Key / Value of the Table; Old Values; New Values ......
Read more >
Entity Change Tracking using DbContext in ...
It allows you to record the entity changed, the value changed, the primary key of the changed record, and the date of change....
Read more >
3 Ways to Implement Auditable Entities in Entity Framework ...
In this article, we'll look at 3 different options that developers can use to implement auditing functionality for domain entities ( CreatedAt , ......
Read more >
Easily adding auditing to a Entity Framework Code First project
This post will show you how to easily do auditing with entity framework projects. ... and then add a new MVC 5 Controller...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found