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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:49:13+00:00 2026-05-20T20:49:13+00:00

I am trying to have a query in a method that looks like this:

  • 0

I am trying to have a query in a method that looks like this:

Public Shared Function listParticipationsByTeamCount(ByVal count As Integer, ByVal challenge As Challenge) As List(Of Participation)
    Dim participationList As List(Of Participation)

    If count <> Nothing And challenge IsNot Nothing Then
        Using db As New DatabaseEntities()
            participationList = db.Participations.Where(Function(x) x.TeamCount = count And x.Challenge.Id = challenge.Id).OrderByDescending(Function(x) x.TeamCount).ThenBy(Function(x) x.Team.Name).ToList()
        End Using
    End If

    Return participationList
End Function

I have a Participation table, that has a many to 1 relationship between Participation and Team table, and a many to many relationship between Participation and TeamMember table. On my markup page I try something like this when I iterate through the list like so:

<% For Each participation As Participation In participationsList%>
    <tr>
        <td><a class="external-link" href="<%= participation.Team.Website %>"><%= participation.Team.Name%></a></td>
        <td><%= participation.Percentage%>%</td>
        <td>
            <%  For Each member As TeamMember In participation.TeamMembers%>
                <%= member.Name%><br /> 
            <% Next%>
        </td>
    </tr>
<% Next%>

I get the following error:

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

Now I understand that is because I put the query inside a using and after the End Using I can’t get the related objects, upon looking this up I tried changing the query the using statement to this:

Using db As New DatabaseEntities()
        participationList = db.Participations.Include("Team").Include("TeamMember").Where(Function(x) x.TeamCount = count And x.Team.Id = team.Id).OrderByDescending(Function(x) x.TeamCount).ThenBy(Function(x) x.Team.Name).ToList()
End Using

This didn’t work. I also tried loading entity references like so:

Using db As New DatabaseEntities()
        participationList = db.Participations.Where(Function(x) x.TeamCount = count And x.Team.Id = team.Id).OrderByDescending(Function(x) x.TeamCount).ThenBy(Function(x) x.Team.Name).ToList()
    For each part as Participation in participationList
            part.TeamReference.Load()
            part.TeamMembers.Load()
    Next
End Using

The error still persisted. How can I load all these related objects into my participationList so I can reference them still after the I End Using??? I know EF4 now does lazyloading by default, but even when I explicitly load related objects it still doesn’t seem to be working.

Edit: Thanks for all the answers all, it was a matter of not pluralizing the TeamMembers include, since it was a collection. This broke the whole query. So the answer is:

Using db As New DatabaseEntities()
        participationList = db.Participations.Include("Team").Include("TeamMembers").Where(Function(x) x.TeamCount = count And x.Team.Id = team.Id).OrderByDescending(Function(x) x.TeamCount).ThenBy(Function(x) x.Team.Name).ToList()
End Using
  • 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-20T20:49:14+00:00Added an answer on May 20, 2026 at 8:49 pm

    In the third code block you are including TeamMember. However, from what I can see in the second code block, your navigation properties are pluralized, so try including TeamMembers instead.

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

Sidebar

Related Questions

I'm have an issue with this entity query that I am hoping to get
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I am trying to build a utility method that will generically load entitycollections using
OK, I'm flummoxed. I'm trying to execute a query on a database (locally) and
I have a Spring application which uses Hibernate on a PostgreSQL database. I'm trying
I've posted this before, but I worded it poorly. I'm trying again with a
I have an array of unknown (to the current method) class objects. I do
I am trying to create a class with various methods that will need to
I had asked this question in a much more long-winded way a few days
I have a website where I allow users to create new Part records. I'm

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.