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 => i.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Token>().HasOne(i => i.User).WithMany(u => u.Tokens);

[...]

#region Properties
// public DbSet<ApplicationUser> Users { get; set; }
public DbSet<Quiz> Quizzes { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Answer> Answers { get; set; }
public DbSet<Result> Results { get; set; }
public DbSet<Token> Tokens { get; set; }
#endregion Properties

[...]

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.255.250