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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:57:13+00:00 2026-05-26T08:57:13+00:00

I have a question regarding the usage of using statements around ObjectContext objects in

  • 0

I have a question regarding the usage of using statements around ObjectContext objects in webforms.

If we have a form setup with two methods, say 'Load()' and 'Save()' and both require usage of the ObjectContext would it be better practice to create an instance variable of the context and use it in both methods, relying on the lifespan of the class to implicitely dispose of the object, or to explicitely create two instances of the object context, wrapped in a using, once per method?

The reason I ask is that I’m unsure of two things. A) whether the overhead of instantiating the object context is high enough to warrant leaving the context open for the entire class to use, or on the flip side B) whether the existence of the object context for the lifespan of the class is too long and we should be explicitely closing it after the unit of work is complete?

Any ideas/suggestions/best practices for this sort of environment?

  • 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-26T08:57:13+00:00Added an answer on May 26, 2026 at 8:57 am

    You can manage the ObjectContext per request, don’t think about it as per Page or WebForm, it has to be bound to the current Request, check here for more details:

    How to Manage ObjectContext Per Request in ASP.NET

    this is more or less also what usually done for NHibernate’ sessions.

    Personally I used to code with a using statement and create/dispose the ObjectContext immediately and in every method I needed it. In some cases you have to pay special attention in this way because your entities will be loaded from one context and saved in another one and I had to attach them back if I recall correct. It has been a while I did so…

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

Sidebar

Related Questions

Good afternoon, I have a quick 'top level' question regarding the usage of Facebook
I have a question regarding the two additional columns (timeCreated, timeLastUpdated) for each record
I have a question regarding dependency injection. say i want to create a class
I have a specific question regarding the usage of profiler. I am new to
I have a question regarding the usage of functions in a command in bash.
I am going over C and have a question regarding const usage with pointers.
I have a few basic questions regarding the syntax and usage of properties in
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION

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.