Use ObjectContext.SavingChanges
event for this purpose.
Handle entities being saved
context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified)
and set your CreatedBy
and UpdatedBy
column values.
http://msdn.microsoft.com/en-us/library/cc716714.aspx
If you are working with DbContext
, use following code to retrieve ObjectContext
from it:
var adapter = (IObjectContextAdapter)dbContext;
var objectContext = adapter.ObjectContext;