Assume table-X holds posts and table-Y holds tags:
public class Post
{
public int Id { get; set; }
public string Title { get; set; }
public virtual ICollection<Tag> Tags { get; set; }
}
public class Tag
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
In this case EF will generate junction table TagPosts for you and query to get all posts which are linked with tags having Id equal to 2 will be:
var query = db.Posts.Where(p => p.Tags.Any(t => t.Id == 2));
Generated SQL query will look like
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Title] AS [Title]
FROM [dbo].[Posts] AS [Extent1]
WHERE EXISTS (SELECT
1 AS [C1]
FROM [dbo].[TagPosts] AS [Extent2]
WHERE ([Extent1].[Id] = [Extent2].[Post_Id]) AND
(2 = [Extent2].[Tag_Id])
)
As you can see, EF is smart enough to check ids in junction table.