void DetachFailedEntities() { foreach (EntityDescriptor entityDescriptor in context.Entities) { if (entityDescriptor.State != EntityStates.Unchanged) { context.Detach(entityDescriptor.Entity); } } }