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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:04:53+00:00 2026-05-28T16:04:53+00:00

I am new to developing in .NET and C#, but have been a long-time

  • 0

I am new to developing in .NET and C#, but have been a long-time developer, working with C, C++, Java, PHP, etc.

I have an MVC3 extension class for my data models that refers to the database. It is set as “private static” in the class, but I think that it is not keeping up with database changes. In other words, when I change data in the controllers, those changes aren’t “noticed” in the db because it is static. Currently, I am creating and disposing of the variable for each use, to compensate.

My questions are:

  1. Am I correct that a static db variable could behave that way?
  2. Is it necessary to dispose of the dynamic variable in the static class, or will garbage collection still take care of it automatically?

Here is a relevant snippet of the class:

namespace PBA.Models {
    using System;
    using System.Text.RegularExpressions;
    using PBA.Models;
    using PBA.Controllers;

    public static class Extensions {
        private static PbaDbEntities db = null;

        public static PbaDbEntities GetDb() {
            // TODO: find out about static memory/disposal, etc.
            //
            if (db != null) {
                db.Dispose();
            }
            db = new PbaDbEntities();
            return db;
        }

        public static string GetCheckpointState(this Activity activity, long memberProjectId) {
            GetDb();  // TODO: Do I need to do this each time, or will a one-time setting work?

            string state = CheckpointController.CHECKPOINT_STATUS_NOT_STARTED;
            try {
                var sub = db.ActivitySubmissions.
                    Where(s => s.activityId == activity.activityId).
                    Where(s => s.memberProjectId == memberProjectId).
                    OrderByDescending(s => s.submitted).
                    First();
                if (sub != null) {
                    state = sub.checkpointStatusId;
                }
            }
            catch (Exception e) {
// omitted for brevity
                }
                return state;
            }
        }
    }
  • 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-28T16:04:55+00:00Added an answer on May 28, 2026 at 4:04 pm

    Your code will fail horribly in production.
    DataContexts are not thread-safe; you must not share a context between requests.

    Never put mutable objects in static fields in multi-threaded applications.

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

Sidebar

Related Questions

I'm new to MVC3 coming from CakePHP, and have been quite impressed. But I've
I have been developing a web application with asp.net and I have smoe question
I have been developing an application in VS2010 and compiling it for the .NET
I have been developing a new MVVM framework here . It has some interesting
I have been developing .NET applications for two years and now I want to
I traditionally work in VB.NET, but have been asked to code the latest project
I am new to Entity Framework but have spend a lot of time reading
I'm developing a new website (ASP.Net, VB codebehind pages, .Net 3.5) to replace a
I'm new here. I'm developing some Asp.Net applications and i wanna test them on
I am new to .NET programming. We are a team of 4 members developing

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.