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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:30:23+00:00 2026-05-12T14:30:23+00:00

I really hope you can help me as I am about to just throw

  • 0

I really hope you can help me as I am about to just throw my MVC/Entity Framework project in the bin and start a MVC/Linq project.

I am building a forum as a project just to get to know MVC/Entity, and I have 4 tables which are all related.

  • Forum_Category,
  • Forum,
  • Topic,
  • Reply

so there is a 1 to many on Category_ID between Forum_Category and Forum.

1 to many on Forum_ID between forum and topic.

and a 1 to many on Topic_ID between Topic and Reply.

I understand that you can load up related data using

Dim F = (From forum in _DataContext.Forum.Include("Forum_Category") _
         Where forum.Forum_ID = 1 _
         Select forum).First

but what if I wanted to get the data for all the replys to a single topic, then load up the topic’s forum and then the category?

I managed to get slightly there with the code:

Dim FT = (From F In _dataContext.Topic.Include("Forum") _
              Where F.TOPIC_STATUS = ForumSettings.FORUM_STATUS.Active _
              Select F).First()
    Dim TRs = (From F In _dataContext.Topic_Reply _
               Where F.Topic.TOPIC_ID = TopicID _
               Select F).ToList()
    For Each TR As Topic_Reply In TRs
        FT.Topic_Reply.Add(TR)
    Next
    Return FT

But then when I tried to add a new Reply, I got the error:
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.

I am totally lost now.

  • 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-12T14:30:24+00:00Added an answer on May 12, 2026 at 2:30 pm
    Dim FT = (From T In _dataContext.Topic.Include("Replies").Include("Forum") _
              Where T.TOPIC_ID = TopicID _
              Select T).First()
    

    …presuming the property is called “Replies” and not “Replys”. 🙂

    Now you can look at FT.Replies to see the reply and FT.Forum to see the Forum.

    Don’t use Add. That’s to do an INSERT into your DB, and of course those records are already there. That’s what the error means.

    The key insight here is that all relationships are two-way. You can see the related object from either side of the relationship.

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

Sidebar

Related Questions

I really hope you can help out here. I'm creating a theme for a
I'm almost losing it, i really hope someone can help me out! I'm using
I have a really hard time understanding routes and I hope someone can help
I'm really confused so I hope you guys can help me. I know how
Really hope someone can help me as I'm a bit stuck :S I have
Really hope someone can help me or at least point me in the right
This is really bugging me, so I hope someone can help me a bit
I have a problem with the esmtp application that I really hope you help
hope to get some help here because this is something that really makes me
I hope there is someone who can help me out here. I have found

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.