Upgrading ApplicationDbContext

The next thing to do is to update the ApplicationDbContext to properly handle the new entity; open the /Data/ApplicationDbContext.cs file and add the following lines to the end of the OnModelCreating() method:

[...]modelBuilder.Entity<ApplicationUser>().ToTable("Users");modelBuilder.Entity<ApplicationUser>().HasMany(u => u.Quizzes).WithOne(i => i.User);modelBuilder.Entity<ApplicationUser>().HasMany(u => u.Tokens).WithOne(i => i.User);[...]modelBuilder.Entity<Result>().ToTable("Results");modelBuilder.Entity<Result>().Property(i => i.Id).ValueGeneratedOnAdd();modelBuilder.Entity<Result>().HasOne(i => i.Quiz).WithMany(u => u.Results);modelBuilder.Entity<Token>().ToTable("Tokens");modelBuilder.Entity<Token>().Property(i ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.