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 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 have an xml file that looks like the following. What I'm trying to
I have a hash being posted to my Rails app that looks like this:
I have a LINQ query that looks like the following: DateTime today = DateTime.UtcNow;
I have below query I am trying to show message 'No SubSource for this
I have a query that I'm trying to figure the django way of doing
I have this query, and I am trying to get the latest comment for
I am trying to have information displayed for this query: SELECT o.sub_number,o.unique_id,o.period_from,o.period_to,o.total_amt, i.paid_amt,i.dated,i.payment,i.paid_by,i.entered_date,i.paid_for_unique, j.cheque_num,j.drawn_on,j.dated
I have this query, which is giving me some problems... I am trying to
I have a SQL query that I'm trying to debug. It works fine for
I have a SQL query that I'm trying to write, but I'm not quite

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.