Я искал последние три часа, пытаясь выяснить, что происходит, и, наконец, пришлось сломать и отправить вопрос.WithRequired() Нет метода расширения
Я пытаюсь добавить WithRequired()/HasRequired() в мой конструктор моделей для ApplicationUser, но он говорит мне, что он не определен.
Я просто совершенно незнакомец здесь, или это изменилось с каркасами .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
@ Дшапиро. Я просто наткнулся на это сам. Благодарю. – RugerSR9
Чтобы помочь другим, не стесняйтесь писать ответ на свой вопрос с тем, что вы сделали, чтобы получить эту работу. – dshapiro