Git Product home page Git Product logo

Comments (3)

ShadySadek avatar ShadySadek commented on August 21, 2024 1

Please i have scenario here , in the following code i am assuming that for-each will be executed twice:
-first loop will be executed successfully and commit the inner transaction.
-second loop will fail and Rollback the inner transaction.

I am expected to find the added rows by the first transaction before rollback the outer transaction but looks like what is happening is rolling back second loop will roll back also first loop

looks like using BeginTransaction within TransactionScope has some issues in addition to the issues with nested transaction in EF6

Any thoughts on this?

 using (var OuterTransactionScope = new TransactionScope())
            {
                using (DbContext = new DbContext())
                {
                    foreach (var x in list) // assume this will be executed twice 
                    {
                        try
                        {
                            var innerTransaction = DbContext.Database.BeginTransaction(isolationLevel);
                            DbContext.SaveChanges(); //Add row
                            DbContext.SaveChanges(); //Add row
                            innerTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            innerTransaction.Rollback();
                        }
                    }
                    //Expecting to find two rows here but Actually no data get added
                }

from ef6.

rowanmiller avatar rowanmiller commented on August 21, 2024

Ported from CodePlex https://entityframework.codeplex.com/workitem/2909

from ef6.

rowanmiller avatar rowanmiller commented on August 21, 2024

Moved to the docs repo as the EF6.x docs are going to end up in the same repo as the EF Core docs. They are going thru a migration process, so changes are difficult right now. dotnet/EntityFramework.Docs#327

from ef6.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.