title: Entity Framework Core - IN clause equivalent
body: <p>I wonder how to convert this sql query to an entity framework query. </p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT * 
  FROM Post
  WHERE PostId IN (
  SELECT PostId FROM BlogPost
  WHERE BlogId = &amp;blogId);
  </code></pre>
  
  <p>I am trying to get a list of Posts with a given category id. </p>
  
  <p>Database simplified: </p>
  
  <p>Blog (the category for the post):</p>
  
  <pre><code>BlogId
  Title
  ..
  </code></pre>
  
  <p>Post:</p>
  
  <pre><code>PostId
  Title
  .. 
  </code></pre>
  
  <p>BlogPost for combining the two tables and letting you have multiple categories per post:</p>
  
  <pre><code>PostId
  BlogId
  </code></pre>
  
  <p>This is what I already have, but ofcourse the query is not working:</p>
  
  <pre class="lang-c# prettyprint-override"><code>public async Task&lt;IActionResult&gt; Category(int? id)
  {
       int blogId = id;
  
       if (blogId == null)
       {
           return NotFound();
       }
       ICollection&lt;Post&gt; posts = await _context.Post.Where(pid =&gt; pid.PostId.Contains(_context.BlogPost.Where(i =&gt; i.PostId == blogId).ToListAsync())).ToListAsync();
  
       if (posts == null)
       {
           return NotFound();
       }
  
       return View(posts );
  }
  </code></pre>
  
  <p>Thank you in advance. </p>