bilal-fazlani / tracker-enabled-dbcontext

Tracker-enabled DbContext offers you to implement full auditing in your database
https://tracker-enabled-dbcontext.bilal-fazlani.com/
Other
217 stars 110 forks source link

Changes dont get audited when "db.Entry(update).State = EntityState.Modified" is used #143

Closed haseebfurkhan closed 7 years ago

haseebfurkhan commented 7 years ago

Hi,

I am using the following code to update my object in MVC application

db.Entry(myObject).State = EntityState.Modified; 
db.SaveChanges();

There are no entries getting saved to AuditLogs or AuditLogDetails tables even though I've made changes to some of the values.

When I create a new record, the changes are getting audited to both the tables.

Tried both TrackerEnabledDbContextv3.6.1 and TrackerEnabledDbContext.Identity v3.6.1

MVC 5.2.2 EntityFramework 6.1.3

Please let me know if I am doing something wrong here, or need to configure more things.

haseebfurkhan commented 7 years ago

Figured it out.

In DB context constructor, set DisconnectedContext to true.

public ApplicationDbContext() : base("DefaultConnection") { GlobalTrackingConfig.DisconnectedContext = true; }