I know you can override the SaveChanges() method in the DbContext object to update audit property values. But what happens when I want to update audit columns without actually mapping them to my entity?
Is there a way to tell Entity Framework to include extra un-mapped column values in the “columns-to-update” list?
Thanks!
Hmm… audit agnostic… So you don’t know if the fields are there to begin with? Or is it that you don’t care if the fields are set?
If the later could you just add the columns but make them not required? I personally add CreatedDate, CreatedBy, ModifiedDate, ModifiedBy to most of my entities via inheritance. I.E. you could have an AuditableEnity class like so:
Then you don’t have to mess up all your models with boilerplate properties. Then you just add a little.
Then your SaveChanges() can look something like this: