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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:28:52+00:00 2026-05-13T09:28:52+00:00

In my project I have about 10 DataContext. My question is whether I have

  • 0

In my project I have about 10 DataContext. My question is whether I have to use global instance or create each single instance of datacontext in a method. Which of the method (from method1 and method2) is better from design point of view.

public class Database
{

    USDataContext USDB = new USCDataContext();

    //Method 1 Global instance
    public void update US_CountryTable()
    {
        USDB.updateCountryTable();
    }

    // Method 2 individual instance
      public void Update CountryTable(string country)
      {
         switch (country)
        {
            case:GB
                GBDataContext GBDB = new GBCDataContext();
                GBDB.updateCountryTable();

                // Some suggest this may be helpful
                // using (GBDataContext  dbContext = new GBDataContext ())
                // { GBDB.updateCountryTable();
                // }
             break;
             case: US
                USDataContext USDB = new USCDataContext();
                USDB.updateCountryTable();
             break;
        } 

      }
}

Thanks

  • 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-13T09:28:53+00:00Added an answer on May 13, 2026 at 9:28 am

    I would actually use a combination of the two approaches. I would use a Singleton class to allow access to a central DataContext handler object, and a secondary class that held the individual data access methods. I would also implement using blocks to make sure my DataContext was initialized clean and disposed fresh with each request.

    public sealed class AppDC
    {
        static readonly ApplicationDataContext _Instance = new ApplicationDataContext();
    
        static AppDC()
        {
        }
    
        AppDC()
        {
        }
    
        public static ApplicationDataContext Instance
        {
            get { return _Instance; }
        }
    }
    
    public static class ApplicationDataContext
    {
        public static void DataAccessOne()
        {
            using (DataContext dc = new DataContext())
            {
                ...
            }
        }
    
        public static void DataAccessTwo()
        {
            using (DataContext dc = new DataContext())
            {
                ...
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my current project I have data about colors. Each color is either a
We have project with a server witch have about 3000 requests at day from
I am asking this question to straighten out a confusion I have about project.clj
I am working on a project and have a question about Java sockets. The
I am beginning a new web project that will have about thirty sites. Each
To simplify the question, I have a single textbox control which I want to
I'm making an Asp.Net MVC 3 project which should have about 10-15 views. How
I am thinking about using Gears in a project, but I have doubts about
I'm about to walk into a project that will have files (mostly PHP) behind
We have a project that’s using many C++11 facilities, and we thought about this

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.