Code Monkey home page Code Monkey logo

Comments (4)

tiesont avatar tiesont commented on July 17, 2024

Your title needs some work; I assume the actual issue is "Inserted item ID not populated"?

You may need to move the last two lines out of the using block; closing the connection to the database should complete the transaction. Otherwise, Context.Entry(address).Reload() might work.

from dbcontextscope.

Danil1985 avatar Danil1985 commented on July 17, 2024

Sorry, but It doesn't working...
When I use a classic TransactionScope with entity-framework it's works very well because when I call context.SaveChanges() => Id property is populated correctly and at the and I call Commit.

But in this case with DbContextScope SaveChages() Do anything when the are parent scope.

from dbcontextscope.

Danil1985 avatar Danil1985 commented on July 17, 2024

Finally,
I try this to replace DbContextScope with TransactionScope
and it's seems to work but I don't know if it's correct approach ?

public int InsertClientWithAddress(Client client, Adresse address)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                int id = Insert(client)
                address.IdClient = id; // =now it's OK
                _addressManager.Insert(address);

                scope.Complete();

                return id;
            }
        }

from dbcontextscope.

glmnet avatar glmnet commented on July 17, 2024

You can overcome this issue by calling SaveChanges from the DbContext (not the DbContextScope) in your implementation of _clientRepository.Add

from dbcontextscope.

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.