Note that there are some explanatory texts on larger screens.

plurals
  1. POado.net entity framework massive confusion
    primarykey
    data
    text
    <p>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.</p> <p>I am building a forum as a project just to get to know MVC/Entity, and I have 4 tables which are all related.</p> <ul> <li>Forum_Category,</li> <li>Forum,</li> <li>Topic,</li> <li>Reply</li> </ul> <p>so there is a 1 to many on Category_ID between Forum_Category and Forum.</p> <p>1 to many on Forum_ID between forum and topic.</p> <p>and a 1 to many on Topic_ID between Topic and Reply.</p> <p>I understand that you can load up related data using</p> <pre><code>Dim F = (From forum in _DataContext.Forum.Include("Forum_Category") _ Where forum.Forum_ID = 1 _ Select forum).First </code></pre> <p>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?</p> <p>I managed to get slightly there with the code:</p> <pre><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 </code></pre> <p>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.</p> <p>I am totally lost now.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload