我一直在寻找过去三个小时试图弄清楚发生了什么,最后不得不分解并发布一个问题。WithRequired()没有扩展方法定义
我想向ApplicationUser的模型构建器添加WithRequired()/ HasRequired(),但它告诉我它没有被定义。
我在这里完全无知,还是因.Net Core/EF Core框架而改变了?
ApplicationUser:
public class ApplicationUser : IdentityUser
{
[Required]
[StringLength(100)]
public string Name { get; set; }
public ICollection<Following> Followers { get; set; }
public ICollection<Following> Followees { get; set; }
public ApplicationUser()
{
Followers = new Collection<Following>();
Followees = new Collection<Following>();
}
}
Following.cs:
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; }
}
ApplicationDbContext:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public DbSet<Gig> Gigs { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Attendance> Attendances { get; set; }
public DbSet<Following> Followings { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
builder.Entity<Attendance>()
.HasKey(c => new { c.GigId, c.AttendeeId });
builder.Entity<ApplicationUser>()
.HasMany(u => u.Followers);
builder.Entity<ApplicationUser>()
.HasMany(u => u.Followees);
}
}
错误,当我尝试添加WithRequired()/ HasRequired():
看起来他们也许改变了你的API:http://stackoverflow.com/questions/31943779/ef-7-beta-6-entities-with-one-to-many-relationships-in-ef-7 – dshapiro
@ dshapiro我实际上只是偶然发现了这一点。谢谢。 – RugerSR9
为了帮助他人,请随时为自己的问题写一个答案,并用你所做的工作来解决问题。 – dshapiro