forked from MicrosoftDocs/mslearn-blazor-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PizzaStoreContext.cs
30 lines (21 loc) · 916 Bytes
/
PizzaStoreContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using Microsoft.EntityFrameworkCore;
namespace BlazingPizza;
public class PizzaStoreContext : DbContext
{
public PizzaStoreContext(
DbContextOptions options) : base(options)
{
}
public DbSet<Order> Orders { get; set; }
public DbSet<Pizza> Pizzas { get; set; }
public DbSet<PizzaSpecial> Specials { get; set; }
public DbSet<Topping> Toppings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Configuración de una relación especial de muchos a muchos -> topping que es amigable para la serialización
modelBuilder.Entity<PizzaTopping>().HasKey(pst => new { pst.PizzaId, pst.ToppingId });
modelBuilder.Entity<PizzaTopping>().HasOne<Pizza>().WithMany(ps => ps.Toppings);
modelBuilder.Entity<PizzaTopping>().HasOne(pst => pst.Topping).WithMany();
}
}