Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8514009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:44:36+00:00 2026-06-11T04:44:36+00:00

I have a problem that I would like to share. The context is a

  • 0

I have a problem that I would like to share. The context is a bit messy, so I will try to do my best in the explanation.

I need to create a transactional operation over a number of entities. I’m working with EF CodeFirst but with a legacy database that I can’t change. In order to create a more consistent model than the database provides I’m projecting the database information into a more refined entities I created on my own.

As I need to use different contexts, my initial idea was to use TransactionScope which gave me good results in the past. Why do I need different contexts? Due to diverse problems with db, I can’t make the updates only in one operation (UnitOfWork). I need to retrieve different IDs which only appears after SaveChanges().

using (var scope = new TransactionScope())
{
    Operation1();
    Operation2();
    Operation3(uses ExecuteStoreCommand)
    SaveChanges();

    Operation4();
    SaveChanges();
}

I know that, in order to use TransactionScope, I need to share the same connection among all the operations (And I’m doing it, passing the context to the objects). However, when I execute one of the operations (which uses ExecuteStoreCommand) or I try to do some update after the first SaveChanges I always receive the MSDTC error (the support for distributed transactions is disabled) or even more rare, as unloaded domains.

I don’t know if someone can help me, at least to know which is the best direction for this scenario.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:44:37+00:00Added an answer on June 11, 2026 at 4:44 am

    Have a look at this answer:
    Entity Framework – Using Transactions or SaveChanges(false) and AcceptAllChanges()?
    The answer does exactly what you require having a transaction, over multiple data contexts.

    This post on Transactions and Connections in Entity Framework 4.0 I found really helpful too.

    For people who may need a simpler solution, here’s what I use when I need to mix ExecuteStoreCommand and SaveChanges in a transaction.

    using (var dataContext = new ContextEntities())
    {
       dataContext.Connection.Open();
       var trx = dataContext.Connection.BeginTransaction();
    
       var sql = "DELETE TestTable WHERE SomeCondition";
       dataContext.ExecuteStoreCommand(sql);
    
       var list = CreateMyListOfObjects(); // this could throw an exception
       foreach (var obj in list)
          dataContext.TestTable.AddObject(obj);
       dataContext.SaveChanges(); // this could throw an exception
    
       trx.Commit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My problem is: I have 3 procs that would like to share config loaded
i have the following problem: i would like to create a footer. that footer
I have an interesting genetics problem that I would like to solve in native
Problem: I have a table that prints out vertical but I would like it
i have a timestamp problem. i would like to check a timestamp if that
I have a problem that is kind of difficult to explain. What I would
I experience strange problem. We have error handling in global.asax that would redirect user
I would like to have the EntityFramework4 model (.edmx and .context.tt) in a Class
I have a problem: I would like to draw a grey overlay on an
We have a website that we would like to extrapolate user controls from and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.