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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:17:07+00:00 2026-05-24T05:17:07+00:00

I have this huge system started running yesterday. Thousands of people connecting simultaneously.. I’m

  • 0

I have this huge system started running yesterday. Thousands of people connecting simultaneously.. I’m Using SQL Server 2008 and .NET 3.5 (C#);

Today I noticed my db server was getting really slow (btw the server machine is really, really capable of handling like 10x this application with ease, so I must be messing up my connections or something).

First of all: My Business classes are creating the only one DataContext each. On class level, like this:

public class BusProduct : IDisposable
{
    //DataContext
    DBDataContext db = new DBDataContext();


    //Variable of type DAL.Products (that will be set on application level)
    public Products _attributes { get; set; }

    //Dispose
    public void Dispose()
    {
        Dispose(true);

        GC.SuppressFinalize(this);
    }

    protected virtual void Dispose(bool disposing)
    {
        if (disposing)
        {
            db.Dispose();
        }
    }

    /// Constructor
    public BusProduct()
    {
        try
        {
            //New object
            _attributes = new Product();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message,ex);
        }
    }

    public void Insert()
    {
        try
        {
            //Insert data set on _attributes
            db.Products.InsertOnSubmit(_attributes);
            db.SubmitChanges();
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message,ex);
        }

    }

}

What do you guys think about this (One DataContext per class)? What would you suggest? Is it good for huge classes? Is it even good?

I Like to make it like this mainly because of returns like IQueryable<Type>. (When trying to access this kind of return, if I use one DataContext for each method, it will already be disposed)

  • 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-24T05:17:07+00:00Added an answer on May 24, 2026 at 5:17 am

    What do you guys think about this (One DataContext per class)?

    What you do is wrong on so many levels it isn’t fun – for example, how do you sync updates on multiple classes in a transaction? A distributed transaction for 200 updates JUST because you don’t care about proper connection handling? This is very expensive. How do you deal with joins and projects between multiple classes? You force different data contexts (one per class) which will result in a total inability of the underlying provider to optimize – not that it is technically impossible, but I am sure the developer will just tell you to sue the stuff properly when asked why it does not take care of it.

    This will require a total rewrite to get into a sensible approach – open a connection when the page starts, close it when the page ends. Well, sometimes more than one if you need separate database transactions, but generally – no.

    Plus get one of those beginner books telling you about the repository pattern. We run all db access throuh a DataManager.

    DataManager contains connection, implements stuffl like Entity which is IQueryable.Open one at the start, use it as you need, finished.

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

Sidebar

Related Questions

I have this huge domain object(say parent) which contains other domain objects. It takes
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a huge problem with this method im trying to make. I have
I have a huge string that looks like this: Text Text Text Text Text
I had a huge file for creating this GUI and I have shortened it
I have a huge autocomplete field with a list of exams. This field prepends
I have this very huge XML file of size 2.8GB. This is Polish Wikipedia's
So, I have built on this system for quite some time, and it is
In our company we have started using VS 2010 to model our systems, in
I'm in the process of creating a more elaborate filtering system for this huge

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.