NFR: Add AuditIncludeExplicitly attribute
In my project I have a problem when something is deleted then only PK key property is saved even if IgnorePropertyUnchanged = false;, but I need all information, at least some referenced keys (FKs)
it will be very good to add AuditIncludeExplicitly (to property), so it will add this property no-matter-what (all cases)
Currently using hack on EFCore context level and works well
public void SetPropertyModified(object entity, string propertyName, bool isModified)
{
var entry = _context.Entry(entity);
var property = entry?.Property(propertyName);
if (property != null)
{
property.IsModified = isModified;
}
}
Hello @ViltusVilks ,
Thank you for your good suggestion.
So you want to include always properties even if unchanged exactly like we do with the primary key.
We will check about this request.
Best Regards,
Jonathan
Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework Extensions • Entity Framework Classic • Bulk Operations • Dapper Plus
Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval Function • SQL Eval Function
Yes, I want to include "navigation" FKs identifiers, so I can grab later history.
Without setting isModified=true hack when You do Remove() on virtual collection (children) audit log is created OK for PK only, but because object was deleted permanently then You can't see what exactly was deleted, and no chance to reconstruct entire tree.
Now I am doing IsModified=true plus delete entity from root DbSet<TEntity>, because we have a bit bigger graph modifications.
current workaround
var rootEntity = context.FirstOrDefault(...);
var forDelete = rootEntity.Childrens.Where(...).ToArray();
foreach (var childEntity in forDelete)
{
// it is needed if you want to walk later
rootEntity.Childrens.Remove(childEntity );
deleteList.Add(childEntity);
}
deleteList.forEach( childEntity => {
// will record all props into log
context.MyTable.Remove(childEntity);
});
Is there any way to do this for EF6? It seems the checking for IsModified is only for EFCore when I glanced at the source.
I have the same case as @ViltusVilks wherein I need to preserve navigation FKs as I will need them when I aggregate related audit tables for viewing for the client.