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 about django signals ( http://docs.djangoproject.com/en/dev/topics/signals/ ), but as far as I understand,
I read a few documents about Mutex and still the only Idea I have
I read about Session Hijacking articles and would like to some more information related
I read this article on the maven project web page that lists the different
I am trying to user the Response.TransmitFile() to prompt a download. I have read
Read a list of files with R, each file contains a list of float
Read that the following code is an example of unsafe construction as it allows
I read that for user-defined types, postponing the defintion of a variable until a
Cannot read http://www.earnforex.com/blog/2010/08/forex-technical-analysis-for-week-0809%E2%80%940813/ how to encode the url to be able to read it
I read in FsUnit that the following are valid method/classnames in F#: [<TestFixture>] type

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.