Recycle all contexts on beginning a write operation for the time being

This commit is contained in:
Dean Herbert 2018-05-30 13:43:25 +09:00
parent e23e2bd348
commit 4a7de043e0
1 changed files with 7 additions and 0 deletions

View File

@ -48,7 +48,14 @@ public DatabaseWriteUsage GetForWrite(bool withTransaction = true)
Monitor.Enter(writeLock);
if (currentWriteTransaction == null && withTransaction)
{
// this mitigates the fact that changes on tracked entities will not be rolled back with the transaction by ensuring write operations are always executed in isolated contexts.
// if this results in sub-optimal efficiency, we may need to look into removing Database-level transactions in favour of running SaveChanges where we currently commit the transaction.
if (threadContexts.IsValueCreated)
recycleThreadContexts();
currentWriteTransaction = threadContexts.Value.Database.BeginTransaction();
}
Interlocked.Increment(ref currentWriteUsages);