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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:39:25+00:00 2026-05-14T05:39:25+00:00

I am working on an existing ASP.NET MVC app that started small and has

  • 0

I am working on an existing ASP.NET MVC app that started small and has grown with time to require a good re-architecture and refactoring.

One thing that I am struggling with is that we’ve got partial classes of the L2S entities so we could add some extra properties, but these props create a new data context and query the DB for a subset of data. This would be the equivalent to doing the following in SQL, which is not a very good way to write this query as oppsed to joins:

SELECT tbl1.stuff, 
    (SELECT nestedValue FROM tbl2 WHERE tbl2.Foo = tbl1.Bar),
    tbl1.moreStuff
 FROM tbl1

so in short here’s what we’ve got in some of our partial entity classes:

public partial class Ticket {

public StatusUpdate LastStatusUpdate
{
    get
    {
         //this static method call returns a new DataContext but needs to be refactored
         var ctx = OurDataContext.GetContext();
         var su = Compiled_Query_GetLastUpdate(ctx, this.TicketId);
         return su;
    }
}

}

We’ve got some functions that create a compiled query, but the issue is that we also have some DataLoadOptions defined in the DataContext, and because we instantiate a new datacontext for getting these nested property, we get an exception

“Compiled Queries across DataContexts
with different LoadOptions not
supported”

. The first DataContext is coming from a DataContextFactory that we implemented with the refactorings, but this second one is just hanging off the entity property getter.

We’re implementing the Repository pattern in the refactoring process, so we must stop doing stuff like the above. Does anyone know of a good way to address this issue?

EDIT: I am adding the code for the DataContextFactory that we created during our refactoring efforts. Note that in the code above we have a GetContext() static method in the Linq DataContext class, which news up a datacontext, and is not using the DataContextFactory below:

public class DataContextFactory<T> : IDataContextFactory where T : System.Data.Linq.DataContext
{
    public DataContextFactory()
    {
        _context = Activator.CreateInstance<T>();
    }

    public DataContextFactory(T context)
    {
        _context = context;
    }

    private System.Data.Linq.DataContext _context;
    public System.Data.Linq.DataContext Context
    {
        get 
        {
            return _context; 
        }
    }

    public void SaveAll()
    {
        Context.SubmitChanges();
    }

    public bool IsContextDirty
    {
        get
        {
            return Context != null && (Context.GetChangeSet().Deletes.Count > 0 ||
                                           Context.GetChangeSet().Inserts.Count > 0 ||
                                           Context.GetChangeSet().Updates.Count > 0);
        }
    }
}
  • 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-14T05:39:26+00:00Added an answer on May 14, 2026 at 5:39 am

    Instead of creating the DataContext whenever the method is called, store it in HttpContext.Current.Items.

    This will achieve the same effect as storing it in a private field, as it will be unique to the request.

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

Sidebar

Related Questions

I'm working on an ASP.NET MVC app that uses a Flash movie as a
I've been working with asp.net MVC and am still not very good at it.
I have an existing ASP.NET web application that I'm converting to MVC 1.0. The
I have an app, modelled on the one from Apress Pro ASP.NET MVC that
I have an existing ASP.NET MVC 2 application that I've been asked to extend.
Background I'm working on building an ASP.Net MVC 3 application that utilizes: JQueryUI for
I am working on implementing Zend Framework within an existing project that has a
We have an existing certificate issuing application (C#, ASP.NET, JavaScript) that issues certificates to
I am working on an existing project that has two areas that can be
So far I've been using ASP.NET MVC 3 BETA. Everything was working fine till

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.