Audit trail with LINQ on db.SubmitChanges()

Objective :

I would like to create a Audit Trail entity in my database. The idea to keep a track of all the inserts, updates and deletes in tables. This table will have columns like Tablename, fieldname, recordid, beforevalue, aftervalue, datechanged, changedby, action(insert,update,delete).

Actually i was searching on this topic “Audit trial with LINQ” and it should happen on db.SubmitChanges() method action. I was expecting some features from LINQ to have this option by default in the latest version. I got tired searching lot of stuff googling and finally i got a blog where one has written a audit trial with LINQ.

Big thanks to Matt for his contribution !

Matt Hidinger:  http://www.matthidinger.com/archive/2009/01/12/linq-audit-trail-v2.aspx

 

matt’s objectives :

Automatic auditing of all inserts/updates/deletes for any table in your database with a single line of code, including:

  • What table was modified?
  • What fields changed?
  • Who made the change?
  • When did it occur?

He created a ER model  like this :

 

Usage : Simply define your audit definitions at any time before calling SubmitChanges();

   1:  this.Products.Audit();  
   2:  this.Categories.Audit();  
   3:  this.Orders.Audit().AuditAssociation(o => o.Order_Details);  
   4:  this.Contacts.Audit().AuditAssociation(c => c.Addresses).AuditAssociation(c => c.PhoneNumbers); 

 

– Ananth Ramasamy Meenachi www.msarm.com

Advertisements

About msarm

Aspiring Enterprise Architect.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s