EntityFramework-Plus icon indicating copy to clipboard operation
EntityFramework-Plus copied to clipboard

NFR: Add AuditIncludeExplicitly attribute

Open ViltusVilks opened this issue 6 years ago • 4 comments

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)

ViltusVilks avatar Mar 01 '19 10:03 ViltusVilks

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;
     }
}

ViltusVilks avatar Mar 01 '19 13:03 ViltusVilks

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 ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan avatar Mar 01 '19 15:03 JonathanMagnan

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);
});

ViltusVilks avatar Mar 01 '19 16:03 ViltusVilks

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.

RyoukoKonpaku avatar Mar 20 '19 10:03 RyoukoKonpaku