title: Get entity by id of sub-class (many-to-many relationship)
body: <p>Entities <code>Topic</code> and <code>Users</code> have a many-to-many relationship. The "table in the middle" is used for a subscription functionality, a <code>User</code> can subscribe to multiple <code>Topic</code>s.</p>
  
  <p>I'm trying to check if an <code>User</code> is subscribed to some <code>Topic</code> or not. If <code>null</code> is returned, then it means that the <code>User</code> is not subscribed to the <code>Topic</code>.</p>
  
  <p>This is the structure:</p>
  
  <pre><code>Topic.Id = topicId
  Topic.Users.FirstOrDefault().Id = userId
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>context
  .Topics
  .Where(t =&gt; t.Id == topicId &amp;&amp; t.Users.FirstOrDefault().Id == userId).FirstOrDefault();
  </code></pre>
  
  <p>The problem is causing this part <code>t.Users.FirstOrDefault()</code> i think... If multiple users are subscribed to the same <code>Topic</code>, then it's working only for one <code>User</code>. It would have to check all <code>Topic.Users</code> and not just the <code>FirstOrDefault()</code>.</p>