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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:36:25+00:00 2026-06-12T17:36:25+00:00

I am new to Linq to sql. And my question is simple. Is it

  • 0

I am new to Linq to sql. And my question is simple.

Is it a good idea to have DataContext as public static member in DAL to act as singleton?

  • 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-12T17:36:26+00:00Added an answer on June 12, 2026 at 5:36 pm

    I generally try to group functionality together for a Data Access class and make that class IDisposable.
    Then you Create your DataContext in your constructor and in your dispose method you run your .dispose() call on the DataContext.

    So then when you need something from that class you can wrap it in a using statement, and make a bunch of calls all using the same DataContext.

    It’s pretty much the same effect as using a Static DataContext, but means you don’t forget to close down the connection, and it seems a bit more OO than making things static.

        public class MyDataAccessClass: IDisposable
        {
          private readonly DbDataContext _dbContext;
    
          public MyDataAccessClass()
          {
              _dbContext = new DbDataContext ();
          }
    
          public void Dispose()
          {
            _dbContext.Dispose();
          }
    
          public List<CoolData> GetStuff()
          {
               var d = _dbContext.CallStuff();
               return d;
          }
        }
    

    Then in your class

       using(var d = new MyDataAccessClass())
       {
             //Make lots of calls to different methods of d here and you'll reuse your DataContext
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im really new to linq-to-SQL so this may sound like a really dumb question,
I am new to LINQ to SQL, but have done a lot of database
I am new to LINQ and EF and I have a quick question about
Hi, I have a linq to sql question like this : tmpAdList1 = (from
I have the following setup for a simple application: generated LINQ to SQL classes
This is probably a pretty simple LINQ question. I'm using LINQ to SQL and
I am quite new with Linq to SQL and MVC but I follow the
New to MVC3 Razor - linq to sql having spent some time trying to
We are using Linq-to-SQL with SQL Server as an ORM on our new project.
I'm new at LINQ, searching the net for LINQ samples that mimic SQL's LIKE

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.