I'm not sure if this is a question about Entity Framework, or how the audit.net library works, but I was guessing it was with how I was performing updates with EF. My goal is to capture only actual changes to the record, but it's capturing everything as change, even if the old and new values are identical.
Basically to simplify it as much as possible, if I do
var existing = context.Appl.FirstOrDefault(a => a.Id == id);
context.Appl.Update(existing);
context.SaveChanges();
(Changing nothing)
The Audit.Net change log says every single field was changed, and looks like
"Changes": [
{
"ColumnName": "FOO",
"OriginalValue": "",
"NewValue": ""
},
..... many more
Then you should not use the
Update
method.According to the
Update
method documentation:The main usage case for
Update
method is to perform a so called forced update when working with Disconnected Entities. Since yourexisting
entity is retrieved from the context (or in other words, is tracked by the context), hence all you need is to set the new values. Change tracker will detect if there are actual property changes and will issueUPDATE
command with only modified values (or noUPDATE
command at all if all current values are equal to the original values).