locked
Can I have multiple DbContext in single transaction RRS feed

  • Question

  • I've bee googling a lot in multiple DbContexts subject, but I still can't got a good answer.

    Can I have a single transaction with multiple Dbcontexts, I don't want to use TransactionScope due to some reason.

    In my project, we use DataContext now, and I can do this

    //  init and setup trans first

    AContext a = new AContext(conn)

    BContext b = new BContext(conn)

    a.Transaction = trans

    b.Transaction = trans

    trans.Commit()

    Is any way in DbContext allow me to do the same things?

    Thanks.

    Friday, December 7, 2012 3:29 AM

All replies

  • Hi,

    I've bee googling a lot in multiple DbContexts subject, but I still can't got a good answer.

    Can I have a single transaction with multiple Dbcontexts, I don't want to use TransactionScope due to some reason.

    In my project, we use DataContext now, and I can do this

    //  init and setup trans first

    AContext a = new AContext(conn)

    BContext b = new BContext(conn)

    a.Transaction = trans

    b.Transaction = trans

    trans.Commit()

    Is any way in DbContext allow me to do the same things?

    Thanks.

    • Merged by Alexander Sun Wednesday, December 12, 2012 7:17 AM Duplicate
    Friday, December 7, 2012 3:27 AM
  • I think this must be something that you are looking for

    http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/thread/34f77081-d3b8-405a-9913-0ce4333e7e9c/


    Please Mark as Reply and Vote as Helpful if I helped.

    Also please visit my blog http://msguy.net/

    Friday, December 7, 2012 2:36 PM
  • I think you need to use MSDTC, otherwise, we cannot use get multiple DbContext being used in a single Transaction.

    Good day!


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 11, 2012 7:50 AM