2023-04-07 10:55:40 +04:00
|
|
|
|
using CanteenDatabaseImplement.Models;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-04-09 00:34:25 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
2023-04-09 19:05:54 +04:00
|
|
|
|
using System.Diagnostics.Contracts;
|
2023-04-07 10:55:40 +04:00
|
|
|
|
|
|
|
|
|
namespace CanteenDatabaseImplement
|
|
|
|
|
{
|
|
|
|
|
public class CanteenDatabase : DbContext
|
|
|
|
|
{
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
if (optionsBuilder.IsConfigured == false)
|
|
|
|
|
{
|
2023-05-16 19:13:19 +04:00
|
|
|
|
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-PA5STI0\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
2023-04-07 10:55:40 +04:00
|
|
|
|
}
|
|
|
|
|
base.OnConfiguring(optionsBuilder);
|
|
|
|
|
}
|
2023-04-09 00:34:25 +04:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.Entity<DishProduct>()
|
|
|
|
|
.HasKey(dp => new { dp.DishId, dp.ProductId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<DishProduct>()
|
|
|
|
|
.HasOne(dp => dp.Dish)
|
|
|
|
|
.WithMany(d => d.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.DishId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<DishProduct>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(p => p.Dishes)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<LunchOrder>()
|
|
|
|
|
.HasKey(dp => new { dp.LunchId, dp.OrderId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchOrder>()
|
|
|
|
|
.HasOne(dp => dp.Lunch)
|
|
|
|
|
.WithMany(d => d.Orders)
|
|
|
|
|
.HasForeignKey(dp => dp.LunchId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchOrder>()
|
|
|
|
|
.HasOne(dp => dp.Order)
|
|
|
|
|
.WithMany(p => p.Lunches)
|
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<LunchProduct>()
|
|
|
|
|
.HasKey(dp => new { dp.LunchId, dp.ProductId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchProduct>()
|
|
|
|
|
.HasOne(dp => dp.Lunch)
|
|
|
|
|
.WithMany(d => d.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.LunchId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchProduct>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(p => p.Lunches)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<OrderCook>()
|
|
|
|
|
.HasKey(dp => new { dp.OrderId, dp.CookId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderCook>()
|
|
|
|
|
.HasOne(dp => dp.Order)
|
|
|
|
|
.WithMany(d => d.Cooks)
|
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderCook>()
|
|
|
|
|
.HasOne(dp => dp.Cook)
|
|
|
|
|
.WithMany(p => p.Orders)
|
|
|
|
|
.HasForeignKey(dp => dp.CookId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<OrderDish>()
|
|
|
|
|
.HasKey(dp => new { dp.OrderId, dp.DishId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderDish>()
|
|
|
|
|
.HasOne(dp => dp.Order)
|
|
|
|
|
.WithMany(d => d.Dishes)
|
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderDish>()
|
|
|
|
|
.HasOne(dp => dp.Dish)
|
|
|
|
|
.WithMany(p => p.Orders)
|
|
|
|
|
.HasForeignKey(dp => dp.DishId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<ProductCook>()
|
|
|
|
|
.HasKey(dp => new { dp.ProductId, dp.CookId });
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ProductCook>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(d => d.Cooks)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ProductCook>()
|
|
|
|
|
.HasOne(dp => dp.Cook)
|
|
|
|
|
.WithMany(p => p.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.CookId)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<Order>()
|
|
|
|
|
.HasOne(b => b.Visitor)
|
|
|
|
|
.WithMany(a => a.Orders)
|
|
|
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 10:55:40 +04:00
|
|
|
|
public virtual DbSet<Cook> Cooks { set; get; }
|
2023-04-07 23:35:33 +04:00
|
|
|
|
public virtual DbSet<OrderCook> OrderCook { set; get; }
|
2023-04-07 10:55:40 +04:00
|
|
|
|
public virtual DbSet<Dish> Dishes { set; get; }
|
|
|
|
|
public virtual DbSet<Lunch> Lunches { set; get; }
|
2023-04-09 00:34:25 +04:00
|
|
|
|
public virtual DbSet<LunchOrder> LunchOrder { set; get; }
|
2023-04-07 10:55:40 +04:00
|
|
|
|
public virtual DbSet<Manager> Managers { set; get; }
|
|
|
|
|
public virtual DbSet<Order> Orders { set; get; }
|
|
|
|
|
public virtual DbSet<Product> Products { set; get; }
|
2023-04-07 23:35:33 +04:00
|
|
|
|
public virtual DbSet<ProductCook> ProductCook { set; get; }
|
|
|
|
|
public virtual DbSet<LunchProduct> LunchProduct { set; get; }
|
2023-04-09 00:34:25 +04:00
|
|
|
|
public virtual DbSet<OrderDish> OrderDish { set; get; }
|
|
|
|
|
public virtual DbSet<DishProduct> DishProduct { set; get; }
|
2023-04-07 10:55:40 +04:00
|
|
|
|
public virtual DbSet<Tableware> Tablewares { set; get; }
|
|
|
|
|
public virtual DbSet<Visitor> Visitors { set; get; }
|
2023-04-09 19:05:54 +04:00
|
|
|
|
|
2023-04-07 10:55:40 +04:00
|
|
|
|
}
|
|
|
|
|
}
|