/// <summary> /// Methods of adding a record in the database (Storage4). /// Called from the methods TransactionScopeWithStorage. /// </summary> /// <param name="context">The context of the interaction with the database.</param> /// <param name="entity">The object to add the type of User.</param> /// <param name="count">Counter.</param> /// <param name="commitCount">Meaning - "every time commitCount doing SaveChanges()".</param> /// <param name="recreateContext">It must be true.</param> /// <returns>The context of the interaction with the database.</returns> private static Storage4Context AddToStorage4(Storage4Context context, User entity, int count, int commitCount, bool recreateContext) { context.Set<User>().Add(entity); if (count%commitCount != 0) return context; context.SaveChanges(); if (!recreateContext) return context; context.Dispose(); context = new Storage4Context(); context.Configuration.AutoDetectChangesEnabled = false; return context; }