title: Correct way to make a query with using of many-to-many relation
body: <p>I've created three tables - Podcast, Category and CategoryLink.
  The CategoryLink table contains only two columns - PodcastId and CategoryId.
  I have described many-to-many relations between these tables as written in this <a href="http://blogs.microsoft.co.il/blogs/gilf/archive/2011/08/01/creating-a-many-to-many-mapping-using-code-first.aspx" rel="nofollow">article</a>.
  All works fine but I don't know how to make query correctly.
  Now I do this by the following way:</p>
  
  <pre><code>var ps = db.Podcasts.Where(p =&gt; p.Status.SysStatus &gt; 0);
  if (category_id.HasValue)
      ps = ps.Where(p =&gt; p.Categories.Where(c =&gt; c.Id == category_id.Value).FirstOrDefault() != null);
  </code></pre>
  
  <p>It works, but I think it's a little dirty way :-)</p>
  
  <p>It give me the following SQL query (I've removed excess columns and strings):</p>
  
  <pre><code>    SELECT 
  [Project2].[Id] AS [Id]
  FROM ( SELECT 
      [Extent1].[Id] AS [Id], 
      (SELECT TOP (1) 
          [Extent3].[CategoryId] AS [CategoryId]
          FROM [dbo].[CategoryLink] AS [Extent3]
          WHERE ([Extent1].[Id] = [Extent3].[PodcastId]) AND ([Extent3].[CategoryId] = 1)) AS [C1]
      FROM  [dbo].[Podcast] AS [Extent1]
      INNER JOIN [dbo].[PodcastStatus] AS [Extent2] ON [Extent1].[StatusId] = [Extent2].[Id]
      WHERE [Extent2].[SysStatus] &gt; 0
  )  AS [Project2]
  WHERE [Project2].[C1] IS NOT NULL
  </code></pre>
  
  <p>The querstion is that how to do query so I can get a 'normal' <code>inner join</code> without sub-queries?</p>
  
  <p>Thanks.</p>