Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created January 27, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavilanch/37b5bb3a5c7316970ea5c8fe3c7e5db4 to your computer and use it in GitHub Desktop.
Save gavilanch/37b5bb3a5c7316970ea5c8fe3c7e5db4 to your computer and use it in GitHub Desktop.
public override int SaveChanges()
{
// Soft-Delete
var entities = ChangeTracker.Entries()
.Where(e => e.State == EntityState.Deleted && e.Metadata.GetProperties()
.Any(x => x.Name == "IsDeleted"))
.ToList();
foreach (var entity in entities)
{
entity.State = EntityState.Unchanged;
entity.CurrentValues["IsDeleted"] = true;
}
return base.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment