在 EF 6 中找不到 HasOne

HasOne not found in EF 6

我是 Entity Framework 的新手,我正在尝试找出关系。我找到了这段代码:

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; }
}

编译代码时出现错误:

'EntityTypeConfiguration' does not contain a definition for 'HasOne' and no extension method 'HasOne' accepting a first argument of type 'EntityTypeConfiguration' could be found (are you missing a using directive or an assembly reference?)

我试图在 Google 和 Whosebug 上找到它,但我找到的唯一东西是如何使用它,而不是它为什么会出现问题。我真的错过了参考吗?如果有,是哪一个?

HasOne() 是一个 Entity Framework 核心方法。

在以前的版本中,您使用 HasOptional() or HasRequired()