How to avoid database locking using EntityFramework Transaction

2

I have a method where I save several classes and call another method to do an optimization on top of these classes, however I am using Transaction , in case something wrong in this optimization I need to give rollback .

Transaction

using (var context = new AppContext())
{
    using (var dbContextTransaction = context.Database.BeginTransaction())
    {

I tried to change the isolationLevel like this:

using (var dbContextTransaction = 
                 context.Database.BeginTransaction(IisolationLevel.snapshot))

But even so, he keeps giving lock to the bank, I would like to know why this happens and how I would do to get around this situation, basically I would like to make a Optimistic concurrency control , without checking the commit, simply latest version is saved.

obs. using some commands directly in the database I get the behavior expected, but it seems to me that the isolationLevel I set in BeginTransaction is not serving anything, if someone can explain the operation and clarify what I'm letting go, I'll be grateful .

Commands used:

ALTER DATABASE [DB] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [DB] SET READ_COMMITTED_SNAPSHOT ON;
ALTER DATABASE [DB] SET ALLOW_SNAPSHOT_ISOLATION ON;
ALTER DATABASE [DB] SET MULTI_USER
    
asked by anonymous 10.11.2018 / 20:43

0 answers