/// <summary> /// Called on the end of the scope. Disposes the ObjectContext. /// </summary> public void Dispose() { if (!_isDisposed) { try { /* End of scope, so clear the thread static * _currentScope member: */ _currentScope = null; Thread.EndThreadAffinity(); if (_saveAllChangesAtEndOfScope) { // Qui ci potrebbero essere delle eccezioni _dbContext.SaveChanges(); } } catch (Exception ee) { _giornale.Error("Salvataggio sul db fallito: " + ErroriUtil.estraiMessage(ee), ee); throw ee; } finally { // In ogni caso devo chiudere tutto _dbContext.Dispose(); _dbContext = null; _isDisposed = true; _giornale.Debug("-Chiudo Unit-Of-Work"); } } else { _giornale.Warn("Come mai casco qui ?? Impossibile. Debuggare!"); if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } } }