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-06-21 19:25:26 +04:00
|
|
|
|
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-A68O3K0;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>()
|
|
|
|
|
.HasOne(dp => dp.Dish)
|
|
|
|
|
.WithMany(d => d.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.DishId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<DishProduct>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(p => p.Dishes)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchOrder>()
|
|
|
|
|
.HasOne(dp => dp.Lunch)
|
|
|
|
|
.WithMany(d => d.Orders)
|
|
|
|
|
.HasForeignKey(dp => dp.LunchId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchOrder>()
|
|
|
|
|
.HasOne(dp => dp.Order)
|
|
|
|
|
.WithMany(p => p.Lunches)
|
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchProduct>()
|
|
|
|
|
.HasOne(dp => dp.Lunch)
|
|
|
|
|
.WithMany(d => d.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.LunchId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<LunchProduct>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(p => p.Lunches)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderCook>()
|
|
|
|
|
.HasOne(dp => dp.Order)
|
|
|
|
|
.WithMany(d => d.Cooks)
|
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<OrderCook>()
|
|
|
|
|
.HasOne(dp => dp.Cook)
|
|
|
|
|
.WithMany(p => p.Orders)
|
|
|
|
|
.HasForeignKey(dp => dp.CookId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
2023-05-19 03:39:58 +04:00
|
|
|
|
modelBuilder.Entity<OrderTableware>()
|
2023-04-09 00:34:25 +04:00
|
|
|
|
.HasOne(dp => dp.Order)
|
2023-05-19 03:39:58 +04:00
|
|
|
|
.WithMany(d => d.Tablewares)
|
2023-04-09 00:34:25 +04:00
|
|
|
|
.HasForeignKey(dp => dp.OrderId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
2023-05-19 03:39:58 +04:00
|
|
|
|
modelBuilder.Entity<OrderTableware>()
|
|
|
|
|
.HasOne(dp => dp.Tableware)
|
2023-04-09 00:34:25 +04:00
|
|
|
|
.WithMany(p => p.Orders)
|
2023-05-19 03:39:58 +04:00
|
|
|
|
.HasForeignKey(dp => dp.TablewareId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ProductCook>()
|
|
|
|
|
.HasOne(dp => dp.Product)
|
|
|
|
|
.WithMany(d => d.Cooks)
|
|
|
|
|
.HasForeignKey(dp => dp.ProductId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ProductCook>()
|
|
|
|
|
.HasOne(dp => dp.Cook)
|
|
|
|
|
.WithMany(p => p.Products)
|
|
|
|
|
.HasForeignKey(dp => dp.CookId)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<Order>()
|
|
|
|
|
.HasOne(b => b.Visitor)
|
|
|
|
|
.WithMany(a => a.Orders)
|
2023-05-20 00:18:48 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<Lunch>()
|
|
|
|
|
.HasOne(b => b.Visitor)
|
|
|
|
|
.WithMany(a => a.Lunches)
|
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<Order>()
|
|
|
|
|
.HasOne(b => b.Visitor)
|
|
|
|
|
.WithMany(a => a.Orders)
|
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
|
//=====================================
|
|
|
|
|
modelBuilder.Entity<Order>()
|
|
|
|
|
.HasOne(b => b.Visitor)
|
|
|
|
|
.WithMany(a => a.Orders)
|
|
|
|
|
.OnDelete(DeleteBehavior.Cascade);
|
2023-04-09 00:34:25 +04:00
|
|
|
|
//=====================================
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
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-05-19 03:39:58 +04:00
|
|
|
|
public virtual DbSet<OrderTableware> OrderTableware { set; get; }
|
2023-04-09 00:34:25 +04:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|