Last post Feb 08, 2017 03:59 AM by JiyaoLee
Jan 10, 2017 10:31 AM|Athar Ali Khan|LINK
I am using generic repository pattern for CRUD operations. I want to audit trail when User modify record. I want to log modified property name, current value and new value. How to log this using EF 6.1.3?
public class DataRepository<TEntity> : IRepository<TEntity> where TEntity : class
public bool Update(TEntity entity)
using (rateEntities entities = new rateEntities())
entities.Entry(entity).State = System.Data.Entity.EntityState.Modified;
catch (Exception exception)
Jan 11, 2017 08:54 AM|Eric Du|LINK
Hi Athar Ali Khan,
According to your description, as far as I know, your wanted technology is tracker-enabled-dbcontext.
It can track the changes in database, also can record new value, record old value, It will also audit the time of change and user who changed/added/deleted the record. I found a tutorial about how to operate it, please refer to this link:
Jan 12, 2017 09:04 AM|Athar Ali Khan|LINK
Thanks for your reply. I am not using DBContext but Entities with generic repository pattern. I found the below link very helpful but I want implement the audit trail on entity framework using generic repository pattern.
Feb 08, 2017 03:59 AM|JiyaoLee|LINK
Athar Ali Khan
I found the below link very helpful but I want implement the audit trail on entity framework using generic repository pattern.
If you want to use generic repository pattern, you can try to create a class(RepositoryBase.cs), and the DataRepository class implement the RepositoryBase class.
Implement the update and some other generic method in the RepositoryBase class, and add the special method in the DataRepository class.
You can get help from (http://codereview.stackexchange.com/questions/19037/entity-framework-generic-repository-pattern).