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

  • Home
  • SEARCH
  • 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 220337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:55:45+00:00 2026-05-11T18:55:45+00:00

I read Rick Strahl’s article about ways to deal with the data context. My

  • 0

I read Rick Strahl’s article about ways to deal with the data context. My DBML is inside a class library, I keep my data context open by creating a static Current method in a separate custom partial class within library.

public partial class DataContext
{
    public static DataContext Current
    {
        get
        {
            DataContext dc = HttpContext.Current.Items["dc"] as DataContext;
            if (dc == null)
            {
                dc = new ImmediacyPageDataContext();
                HttpContext.Current.Items["dc"] = dc;
            }

            return dc;
        }
    }

then access it like this

DataContext dc = DataContext.Current;

However, this causes issues whenever I update my DBML file. After editing the DBML file whenever I try and build the project my designer file doesn’t regenerate/gets deleted. If I try running the custom tool option it comes back with an error.

The only way I can get round this is by renaming or deleting the custom partial class, re-generating the designer file, then adding my custom partial class back into the solution. This is a does work, but.. its a bit of a pain.

Is there a better approach to take that will make editing my DBML files easier, while prolonging my DC for as long as possible ?

  • 1 1 Answer
  • 1 View
  • 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-11T18:55:45+00:00Added an answer on May 11, 2026 at 6:55 pm

    Go into the code file with your partial DataContext class and move your using statements into your namespace. For some reason the tool will not generate the designer unless this is the case.

    namespace MyNamespace
    {
        using System;
        using System.Data.Linq;
        using System.Data.Linq.Mapping;
        using System.Reflection;
        using System.Xml.Linq;
    
        partial class DataContext
        {
        }
    }
    

    I believe this change was required when moving from VS2008 to VS2008 SP1, though I may be mixing up some versions.

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

Sidebar

Related Questions

I read Rick Strahl's post about DataContext lifetime management, and some of the other
I've read Rick Strahl's article on Linq to SQL DataContext Lifetime Management hoping to
Read about Server push here . I want to push data to client from
I read an article about a regular expression to detect base64 but when I
Read about Fog: http://fog.io Does Python have anything like it? (a library for cloud
Read about the issue in this stackoverflow question . Still have the same issue
Iv read a lot of search results regarding how to deal with a JSON
read a lot about DataAdapter, DataTable ,.. to reach to this code, in the
Read this question today about safe and unsafe code I then read about it
Read some texts about locking in PHP. They all, mainly, direct to http://php.net/manual/en/function.flock.php .

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.