protected virtual void DeleteEntity <T>(T entity) where T : class { NavigationBackupSet backupSet = null; try { backupSet = NavigationBackup <T> .BackupAndReset(entity); Context.Write <T>().Attach(entity); Context.Write <T>().Remove(entity); Context.SaveChanges(); } finally { NavigationBackup <T> .Restore(entity, backupSet); } }
protected virtual void UpdateEntity <T>(T entity) where T : class { NavigationBackupSet backupSet = null; try { backupSet = NavigationBackup <T> .BackupAndReset(entity); Context.Entry(entity).State = EntityState.Modified; Context.SaveChanges(); Context.Entry(entity).State = EntityState.Detached; } finally { NavigationBackup <T> .Restore(entity, backupSet); } }