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 6330823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:56:27+00:00 2026-05-24T17:56:27+00:00

Working on Transactions in .net. Had a question on flowing transactions through sub functions.

  • 0

Working on Transactions in .net. Had a question on flowing transactions through sub functions. Do I need to use dependent transactions if the object context is common across the sub – methods?

For example, in the following code – I declare the object context in the constructor of my class (not sure if this is best practice)

public class EmployeeRepository
{
    private EmployeeContext ec;        
    public EmployeeRepository()
    {
        objectContext = new EmployeeContext();            
    }       
    public InitTransaction(EmployeeEntity emp1)
    {
         using (TransactionScope transaction = new TransactionScope())
        {
            try
            {   ec.employees.AddObject(emp1);
                SubFunction1();
                ec.SaveChanges();                               
            }
            catch
            {
                //catch 
            }
        }
        //commit the transaction here 
        ec.AcceptAllChanges();
    }

    public SubFunction1()
    {
        //some processing 
        //using same object context
        ec.someother.AddObject(someobject);
        ec.SaveChanges();
    }
}

I want the subfunctions to be a part of the transactions as well?
In this case should I use a dependent transaction within SubFunction1 even though I am using the same object context? Or Should I add a

using (TransactionScope transaction = new TransactionScope());

within SubFunction1. Pointers in the right direction would be greatly appreciated.

  • 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-05-24T17:56:27+00:00Added an answer on May 24, 2026 at 5:56 pm

    Transaction Scopes can be nested (they work similar to the SQL @@TRANCOUNT mechanism), so you could in theory use TransactionScopes in your Repository, e.g. to keep parent : child table relationships ACID, but also in your Business / Service layers as well (e.g. to have a Distributed Transaction across multiple entities, possible across multiple Databases, and even across other resources such as Message Queues and Transactional file systems.

    Note that the default isolation level of TransactionScope is Read Serializable – this can lead to locking / deadlocks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a .Net 2.0 application and need to wrap some database transactions
Context: ASP.NET MVC 2.0, Linq-to-Sql, .Net 3.5, IIS7, MS SQL 2008 I'm working on
I'm working with ASP.NET(VB.NET), SQL 2008 Project. I need to write data to more
In my just-completed project, I was working getting distributed transactions working. We implemented this
I did a simple test to understand how transactions work in .net Sample code
Working with MonoTouch .NET for iPhone and SQLite on Mac OSX. I can read
I'm working on a windows application project using front end vb.net & back end
I currently have an application making use of Authorize.net's ARB API. I have everything
Coming from ASP.NET I'm having a hard time with basic ADF concepts. I need
I have a project that I have recently started working on seriously but had

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.