internal static void DeleteAllInternal <T>(this IEnumerable list) { try { DbContextHelper <T> .BeginOperation(); foreach (var t1 in list) { ((IDwarf)t1).Delete(); } DbContextHelper <T> .FinalizeOperation(false); } catch (Exception e) { DbContextHelper <T> .FinalizeOperation(true); DwarfContext <T> .GetConfiguration().ErrorLogService.Logg(e); throw; } finally { DbContextHelper <T> .EndOperation(); } }
/// <summary> /// See base /// </summary> public void Delete() { if (!IsSaved) { return; } try { DbContextHelper <T> .BeginOperation(); OnBeforeDeleteInternal(); OnBeforeDelete(); DwarfContext <T> .GetDatabase().Delete(this); DbContextHelper <T> .FinalizeOperation(false); OnAfterDeleteInternal(); OnAfterDelete(); } catch (Exception e) { DbContextHelper <T> .FinalizeOperation(true); DwarfContext <T> .GetConfiguration().ErrorLogService.Logg(e); throw; } finally { DbContextHelper <T> .EndOperation(); } }
/// <summary> /// Deletes a ManyToMany relationship /// </summary> private static void DeleteManyToMany(IDwarf owner, IDwarf child, string alternateTableName = null) { try { DbContextHelper <T> .BeginOperation(); DwarfContext <T> .GetDatabase().DeleteManyToMany <T>(owner, child, alternateTableName); DbContextHelper <T> .FinalizeOperation(false); } catch (Exception e) { DbContextHelper <T> .FinalizeOperation(true); DwarfContext <T> .GetConfiguration().ErrorLogService.Logg(e); throw; } finally { DbContextHelper <T> .EndOperation(); } }
/// <summary> /// A quick way to insert a lot of objects at the same time. No audit logs are created though /// </summary> protected static void BulkInsert(IEnumerable <T> objects) { try { DbContextHelper <T> .BeginOperation(); DwarfContext <T> .GetDatabase().BulkInsert(objects); DbContextHelper <T> .FinalizeOperation(false); } catch (Exception e) { DbContextHelper <T> .FinalizeOperation(true); DwarfContext <T> .GetConfiguration().ErrorLogService.Logg(e); throw; } finally { DbContextHelper <T> .EndOperation(); } }
/// <summary> /// Default constructor /// </summary> internal TransactionWrapper() { DbContextHelper <T> .BeginOperation(); }
/// <summary> /// See base /// </summary> public void Save() { if (isDeleted) { return; } try { DbContextHelper <T> .BeginOperation(); if (!Id.HasValue) { Id = internallyProvidedCustomId.HasValue ? internallyProvidedCustomId : Guid.NewGuid(); } OnBeforeSave(); var faultyForeignKeys = FaultyForeignKeys(this).ToList(); if (faultyForeignKeys.Count > 0) { DbContextHelper <T> .RegisterInvalidObject(this, faultyForeignKeys); DbContextHelper <T> .FinalizeOperation(false); return; } else { DbContextHelper <T> .UnRegisterInvalidObject(this); } var auditLogType = AuditLogTypes.Updated; var traces = CreateTraceEventsForProperties(); if (IsSaved) { if (traces.Length > 0) //IsDirty { DwarfContext <T> .GetDatabase().Update(this, traces.Select(x => PropertyHelper.GetProperty <T>(x.PropertyName))); } } else { auditLogType = AuditLogTypes.Created; DwarfContext <T> .GetDatabase().Insert <T, T>(this, Id); } CreateAuditLog(auditLogType, traces); PersistOneToManyCollections(); PersistManyToManyCollections(); OnAfterSave(); DbContextHelper <T> .FinalizeOperation(false); OnAfterSaveInternal(); } catch (Exception e) { DbContextHelper <T> .FinalizeOperation(true); DwarfContext <T> .GetConfiguration().ErrorLogService.Logg(e); throw; } finally { DbContextHelper <T> .EndOperation(); } }