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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:26:34+00:00 2026-05-16T22:26:34+00:00

Ok please excuse my references to the gridview. So I have this method in

  • 0

Ok please excuse my references to the gridview.

So I have this method in a class called getall() what this does is gets the collection of entites from entity framework model for a specfic table, checks to see whether the table exists and then does the query using linq (linq to entities). This does work as I have used a breakpoint and even created a seperate test project in order to test it. However when binding it with a gridview has proven difficult for me.

This is the code I used:

protected void Button2_Click(object
sender, EventArgs e)

    {
        dCollection d = new dCollection();

        GridView1.DataSource = d.GetAll();
        GridView1.DataBind();
    }

However I get an error saying:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. 

I’m using a collection to get all my methods from the class dcollection and one of my methods is getall, which will get all records from the table. Why does this not work?

  • 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-16T22:26:35+00:00Added an answer on May 16, 2026 at 10:26 pm

    This error comes from the fact that you have bindings to some navigation properties inside your GridView that has NOT been loaded yet. Therefore when you call the DataBind() it tries to “Lazy Load” those navigation properties and as this happens outside of your ObjectContext living scope (i.e. it has been already disposed) you’ll get this error.

    The solution is to either “Eager Load” all of the nav properties that your GridView is using or disable Lazy Loading on your object context.

    In your case, I would suggest to always disable Lazy Loading regardless of whether or not you eager load the nav properties since it’s a good practice for Web applications like this to always disable Lazy Loading. Once it is disabled, you can still explicitly load related data on demand if needed, or eager load them with the initial query.

    This post contains a more detailed discussion on this issue as well as how you can disable Lazy Loading.

    By the way, the reason your Test Project works is becasue you do not access those “not loaded” nav properties in there, therefore LazyLoading does not happens.

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

Sidebar

Related Questions

Here's one I have always wondered about... Please excuse my naivety, but - How
Ok, I'm an MVC newbie coming from a webforms background, so please excuse any
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
here is what I have (please excuse the crappy art): ------------------------------------------ |Menu | |----------------------------|
I'm new to this so please excuse my presumably simple questions. Hope you'll be
I'm a new programmer, so please excuse any dumbness of this question, how the
Please excuse me for being thick (or not) but does a FaceBook iframe (canvas)
Im testing out something here,so please excuse the css rules.I have got a ul
Please excuse the vague title. If anyone has a suggestion, please let me know!
Please excuse my ignorance on the topic, as I am relatively new to Hibernate

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.