'EF6 allow read but disable insert/update/delete during transaction
I am doing some "sync" between different platform. During this sync I try to add/update/remove records. For it I'm wrapping all functionality in TransactionScope
using (var tx = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.Serializable
},
TransactionScopeAsyncFlowOption.Enabled)) { //logic }
But while transaction is alive and user go to website, requests wait untill transaction is commited or rollbacked. I want to omit this and allow user to see data.
I read that for this case I can do SELECT and it will allow requests to read data from db. As I'm working on sync only with 2 entities, I thought it will be enough to select only for this 2 entities. But it doesn't working. Is there any other ways?
using (var tx = new TransactionScope(TransactionScopeOption.Required,
new TransactionOptions
{
IsolationLevel = IsolationLevel.Serializable
},
TransactionScopeAsyncFlowOption.Enabled))
{
_repositoryForEntity1.AsQueryable().LoadAsync();
_repositoryForEntity2.AsQueryable().LoadAsync();
// Add/Update/Delete logic
uow.SaveChanges();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|