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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:54:51+00:00 2026-05-16T20:54:51+00:00

I hope this makes sense. I have a ASP.NET web application that uses Entity

  • 0

I hope this makes sense. I have a ASP.NET web application that uses Entity Framework. I have added a couple of custom tables to the db and created a separate project to handle the CRUD operations for those tables. I chose the separate project because I don’t want future upgrades to the application to overwrite my custom features.

My problem is this. How do I attach/combine my custom ObjectContext to the ObjectContext of the application? I want to use the same UnitOfWorkScope (already in the application) to maintain the one ObjectContext instance per HTTP request. Again, I don’t want to add my ObjectSets to the application’s ObjectContext for my reason listed above.

Here is some code:

Widget.cs

public partial class Widget
{
public Widget()
{
}
public int WidgetId {get;set;}
public string WidgetName {get;set;}
}

WidgetObjectContext.cs

public partial class WidgetObjectContext : ObjectContext
{
private readonly Dictionary<Type, object> _entitySets;

public ObjectSet<T> EntitySet<T>()
where T : BaseEntity
{
var t = typeof(T);
object match;
if(!_entitySets.TryGetValue(t, out match))
{
match = CreateObjectSet<T>();
_entitySets.Add(t, match);
}
return (ObjectSet<T>)match;
}

public ObjectSet<Widget> Widgets
{
get
{
if((_widgets == null))
{
_widgets = CreateObjectSet<Widget>();
}
return _widget;
}
}
private ObjectSet<Widget> _widgets;

In my WidgetManager class if I was using the application’s ObjectContext I would query my tables like this:

var context = ObjectContextHelper.CurrentObjectContext;
var query = from c in context.ObjectSet .... etc

What I want would be to do something like this:

var context = ObjectContextHelper.CurrentObjectContext.Attach(WidgetObjectContext);

I know this won’t work but that is the gist of what I am trying to accomplish. Hope this is clear enough. Thanks.

  • 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-16T20:54:52+00:00Added an answer on May 16, 2026 at 8:54 pm

    I don’t think it is possible. ObjectContext creates entity connection which connects to metadata describing mapping and database. But you have to different sets of metadata – one for ASP.NET application and one for separate project. Simply you need two connection to work with these models => you need two ObjectContexts.

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

Sidebar

Related Questions

I hope this makes sense. I have a Windows Phone 7 app that is
I have a callback function within an ASP.NET Web Forms application which I am
I hope this makes sense... It doesn't only apply to c#, but that is
I am just getting started with expression trees so I hope this makes sense.
I'm relatively new to web application programming so I hope this question isn't too
I have a scenario that I'm not sure how to handle in ASP.NET. I
I hope I can explain this clearly enough. I have my main form (A)
now that I've resolved my previous issue with clickatell: Impementing Clickatell CallBack in ASP.NET
I hope this question does not come off as broad as it may seem
I hope this question is not considered too basic for this forum, but we'll

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.