Created
August 22, 2014 12:12
-
-
Save ro31337/988c78c5f139d3d6da52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SoftDelete(DbEntityEntry entry) | |
{ | |
Type entryEntityType = entry.Entity.GetType(); | |
string tableName = GetTableName(entryEntityType); | |
string primaryKeyName = GetPrimaryKeyName(entryEntityType); | |
string sql = | |
string.Format( | |
"UPDATE {0} SET IsDeleted = 1 WHERE {1} = @id", | |
tableName, primaryKeyName); | |
Database.ExecuteSqlCommand( | |
sql, | |
new SqlParameter("@id", entry.OriginalValues[primaryKeyName])); | |
// prevent hard delete | |
entry.State = EntityState.Detached; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment