title: Many-to-many query in Entity Framework 7
body: <p>I am following this example which I got from <a href="http://ef.readthedocs.org/en/latest/modeling/relationships.html" rel="nofollow noreferrer">http://ef.readthedocs.org/en/latest/modeling/relationships.html</a></p>
  
  <pre><code>class MyContext : DbContext
  {
      public DbSet&lt;Post&gt; Posts { get; set; }
      public DbSet&lt;Tag&gt; Tags { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;PostTag&gt;()
              .HasKey(t =&gt; new { t.PostId, t.TagId });
  
          modelBuilder.Entity&lt;PostTag&gt;()
              .HasOne(pt =&gt; pt.Post)
              .WithMany(p =&gt; p.PostTags)
              .HasForeignKey(pt =&gt; pt.PostId);
  
          modelBuilder.Entity&lt;PostTag&gt;()
              .HasOne(pt =&gt; pt.Tag)
              .WithMany(t =&gt; t.PostTags)
              .HasForeignKey(pt =&gt; pt.TagId);
      }
  }
  
  public class Post
  {
      public int PostId { get; set; }
      public string Title { get; set; }
      public string Content { get; set; }
  
      public List&lt;PostTag&gt; PostTags { get; set; }
  }
  
  public class Tag
  {
      public string TagId { get; set; }
  
      public List&lt;PostTag&gt; PostTags { get; set; }
  }
  
  public class PostTag
  {
      public int PostId { get; set; }
      public Post Post { get; set; }
  
      public string TagId { get; set; }
      public Tag Tag { get; set; }
  }
  </code></pre>
  
  <p>Now my question is how would I construct my query to get posts given TagId?  Something like:</p>
  
  <pre><code>public List&lt;Post&gt; GetPostsByTagId(int tagId)
  {
      //linq query here
  }
  </code></pre>
  
  <p>Please keep in mind this is EF7.</p>