Create Model for ApplicationUsers that has Followers and Followees using EntityFramework Core 2.1

48 views Asked by At

I'm trying to generate a model for and AspnetUser that has one-to-many relationships with Followers and Followees. The Following Class is defines as:

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

The following worked in EntityFramework but not in 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);
    }

Any help figuring this out greatly appreciated.

0

There are 0 answers