using IdentityServer4.EntityFramework.Options; using Microsoft.AspNetCore.ApiAuthorization.IdentityServer; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace BlazingPizza.Server { public class PizzaStoreContext : ApiAuthorizationDbContext { public PizzaStoreContext( DbContextOptions options, IOptions operationalStoreOptions) : base(options, operationalStoreOptions) { } public DbSet Orders { get; set; } public DbSet Pizzas { get; set; } public DbSet Specials { get; set; } public DbSet Toppings { get; set; } public DbSet NotificationSubscriptions { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // Configuring a many-to-many special -> topping relationship that is friendly for serialization modelBuilder.Entity().HasKey(pst => new { pst.PizzaId, pst.ToppingId }); modelBuilder.Entity().HasOne().WithMany(ps => ps.Toppings); modelBuilder.Entity().HasOne(pst => pst.Topping).WithMany(); // Inline the Lat-Long pairs in Order rather than having a FK to another table modelBuilder.Entity().OwnsOne(o => o.DeliveryLocation); } } }