我正在尝试为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);
}
任何帮助弄清楚这一点的人都将不胜感激。