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