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

The Archive Base Latest Questions

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

I have been adding partial classes of my different entities to add various useful

  • 0

I have been adding partial classes of my different entities to add various useful methods without issue.

Attempting to add properties appears to be straightforward based on examples that I’ve seen, but mine are failing miserably.

Updated example:

        public List<Friend> FriendsInGoodStanding
    {
        get
        {
            using (var context = new GarbageEntities())
            {
                var a = context.Friends.Include("aspnet_User1").Where(f => f.UserID == this.UserId && f.Blocked == false).ToList();
                var b = context.Friends.Include("aspnet_User").Where(f => f.FriendUserID == this.UserId && f.Blocked == false).ToList();
                a.AddRange(b);
                return a.Distinct().ToList();
            }
        }
    }

I am receiving the following error any time I attempt to make use of this property:

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

Line 4936:            get
Line 4937:            {
Line 4938:                return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<aspnet_User>("GarbageModel.FK_Friends_aspnet_Users", "aspnet_User").Value;
Line 4939:            }

This must be something obvious that I’ve overlooked.

  • 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-16T21:51:22+00:00Added an answer on May 16, 2026 at 9:51 pm

    The source of this error is because your program is trying to “Lazy Load” one of the navigation properties on your Friend entity object and this happens when you already read the FriendsInGoodStanding property and the objectcontext has been disposed, because of the using statement.

    Now, I can see that you are eager loading “aspnet_User1” and also you are calling ToList() at the end of your query so it must be another navigation property on the Friend object. If you show the client code that uses the FriendsInGoodStanding property then I can exactly tell which one is that but for now my hunch is that you have a property named aspnet_User on Friend object which also needs to be eager load like this:

    public partial class aspnet_User{
    
        public List FriendsInGoodStanding {
            get {
                using (var context = new GarbageEntities()) {
    
                    var a = context.Friends
                         .Include("aspnet_User1")
                         .Include("aspnet_User")
                         .Where(f => f.UserID == this.UserId && f.Blocked == false).ToList();
    
                    var b = context.Friends
                         .Include("aspnet_User")
                         .Include("aspnet_User1")
                         .Where(f => f.FriendUserID == this.UserId && f.Blocked == false).ToList();
                    a.AddRange(b);
                    return a.Distinct().ToList();
                }
            }
        }
    }
    

    Another Solution:

    would be to disable lazy loading for your object context to get over with this exception. You can do so by right clicking on your model and then selecting properties and then find “Lazy Loading Enabled” option which is true by default, just set it to false. Or programmatically you can code:

    var context = new GarbageEntities();
    context.ContextOptions.LazyLoadingEnabled = false;
    

    Once it is disabled, you can still explicitly load related data on demand if needed, or
    even load the data along with the initial query.
    Just watch out for NullReferenceException!

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

Sidebar

Related Questions

I have been adding items to tool strip by programming but the issue is
I have been adding dependency injection to my code because it makes by code
Recently we have been adding automated tests to our existing java applications. What we
I have a small database and have been adding entries through a Rails page.
I am working on a server-side framework. Here and there I have been adding
I am currently moving into the web-hosting league. I have to far been adding
I have been given the task of adding functionality to an existing IIS 6.0
I've taught myself Obj-C, and have been self-teaching Cocoa, but adding Core Data to
Have been studying the file system related classes of Adobe AIR 1.5, but so
I am a jquery newbie and have been adding alert timestamps into my html

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.