From 48e52db40eb97d2499f1bd6a84d7f70c77b0dc22 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 30 Apr 2024 23:03:49 +0400 Subject: [PATCH] fix ForeignKey constraints in DB models --- ComputerShopDatabaseImplement/Models/Assembly.cs | 5 ++++- ComputerShopDatabaseImplement/Models/Component.cs | 3 +++ ComputerShopDatabaseImplement/Models/Product.cs | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ComputerShopDatabaseImplement/Models/Assembly.cs b/ComputerShopDatabaseImplement/Models/Assembly.cs index 1c4fc2e..fa1548b 100644 --- a/ComputerShopDatabaseImplement/Models/Assembly.cs +++ b/ComputerShopDatabaseImplement/Models/Assembly.cs @@ -21,9 +21,12 @@ namespace ComputerShopDatabaseImplement.Models [Required] public string Category { get; private set; } = string.Empty; - [ForeignKey("ComponentId")] + [ForeignKey("AssemblyId")] public virtual List Components { get; set; } = new(); + [ForeignKey("AssemblyId")] + public virtual List Requests { get; set; } = new(); + private Dictionary? _assemblyComponents; [NotMapped] diff --git a/ComputerShopDatabaseImplement/Models/Component.cs b/ComputerShopDatabaseImplement/Models/Component.cs index bb3251a..39514ae 100644 --- a/ComputerShopDatabaseImplement/Models/Component.cs +++ b/ComputerShopDatabaseImplement/Models/Component.cs @@ -19,6 +19,9 @@ namespace ComputerShopDatabaseImplement.Models [Required] public double Cost { get; private set; } + [ForeignKey("ComponentId")] + public virtual List ProductComponents { get; set; } = new(); + [ForeignKey("ComponentId")] public virtual List AssemblyComponents { get; set; } = new(); diff --git a/ComputerShopDatabaseImplement/Models/Product.cs b/ComputerShopDatabaseImplement/Models/Product.cs index 93aef22..63623c1 100644 --- a/ComputerShopDatabaseImplement/Models/Product.cs +++ b/ComputerShopDatabaseImplement/Models/Product.cs @@ -23,7 +23,9 @@ namespace ComputerShopDatabaseImplement.Models public int? ShipmentId { get; set; } - [ForeignKey("ComponentId")] + public virtual Shipment? Shipment { get; set; } + + [ForeignKey("ProductId")] public virtual List Components { get; set; } = new(); private Dictionary? _productComponents;