protected virtual void Dispose(bool disposing) { if (disposing) { // Clean up 'myElement'. Do this in a new PISystems context - the // current context might be corrupt due to the nature of some // of the assertions we plan to make. myElement = new PISystems(true).Find <AFElement>(elementPath); myElement.UndoCheckOut(true); myElement.Elements.ToList().ForEach(x => x.Delete()); myElement.Database.CheckIn(); // Restore default values. AFGlobalSettings.CacheMaxObjects = 10000; AFGlobalSettings.CacheTime = 120; } }