使用EntityFramework Core 2.1为具有关注者和被关注者的ApplicationUsers创建模型

时间:2019-06-04 17:12:50

标签: asp.net-core-2.1 entity-framework-core-2.1

我正在尝试为AspnetUser和与Followers和Followees建立一对多关系的模型生成一个模型。以下类定义为:

public class Following
{
    [Key]
    [Column(Order = 1)]
    public string FollowerId { get; set; }

    [Key]
    [Column(Order = 2)]
    public string FolloweeId { get; set; }

    public ApplicationUser Follower { get; set; }
    public ApplicationUser Followee { get; set; }
}

以下内容在EntityFramework中有效,但在EntityFramework Core中无效。

protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<ApplicationUser>()
            .HasMany(u => u.Followers)
            .WithRequired(f => f.Followee)
            .WillCascadeOnDelete(false);

        modelBuilder.Entity<ApplicationUser>()
            .HasMany(u => u.Followees)
            .WithRequired(f => f.Follower)
            .WillCascadeOnDelete(false);

        base.OnModelCreating(modelBuilder);
    }

任何帮助弄清楚这一点的人都将不胜感激。

0 个答案:

没有答案