correcting the foreign key in the dish

This commit is contained in:
Николай 2023-03-28 16:41:11 +04:00
parent 1367f37578
commit 118f2aaaff
3 changed files with 9 additions and 5 deletions

View File

@ -93,7 +93,8 @@ namespace FoodOrdersDatabaseImplement.Implements
using var context = new FoodOrdersDatabase();
var element = context.Dishes
.Include(x => x.Components)
.FirstOrDefault(rec => rec.Id == model.Id);
.Include(x => x.Orders)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Dishes.Remove(element);

View File

@ -39,7 +39,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Components");
b.ToTable("Components", (string)null);
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Dish", b =>
@ -59,7 +59,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Dishes");
b.ToTable("Dishes", (string)null);
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>
@ -85,7 +85,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.HasIndex("DishId");
b.ToTable("DishComponents");
b.ToTable("DishComponents", (string)null);
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
@ -118,7 +118,7 @@ namespace FoodOrdersDatabaseImplement.Migrations
b.HasIndex("DishId");
b.ToTable("Orders");
b.ToTable("Orders", (string)null);
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.DishComponent", b =>

View File

@ -35,6 +35,9 @@ namespace FoodOrdersDatabaseImplement.Models
[ForeignKey("DishId")]
public virtual List<DishComponent> Components { get; set; } = new();
[ForeignKey("DishId")]
public virtual List<Order> Orders { get; set; } = new();
public static Dish Create(FoodOrdersDatabase context, DishBindingModel model)
{
return new Dish()