From 3b332d1fe9a60798a981b06565859dede217c560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Tue, 30 Apr 2024 21:59:22 +0400 Subject: [PATCH] ForeignKey --- .../ElectronicsShopDataBaseImplement/Models/Order.cs | 2 +- .../ElectronicsShopDataBaseImplement/Models/OrderProducts.cs | 5 +++-- .../ElectronicsShopDataBaseImplement/Models/Product.cs | 3 ++- .../ElectronicsShopDataBaseImplement/Models/User.cs | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs index 428f670..966a181 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs @@ -18,7 +18,7 @@ namespace ElectronicsShopDataBaseImplement.Models public int ID { get; set; } [Required] public double Sum { get; set; } - [Required] + [ForeignKey("UserID")] public int UserID { get; set; } [Required] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs index 11a056e..2365706 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/OrderProducts.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,10 +12,10 @@ namespace ElectronicsShopDataBaseImplement.Models { public int ID { get; set; } - [Required] + [ForeignKey("OrderID")] public int OrdersID { get; set; } - [Required] + [ForeignKey("ProductID")] public int ProductID { get; set; } [Required] diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs index 9bcbbfe..414403a 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Product.cs @@ -4,6 +4,7 @@ using ElectronicsShopDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -17,7 +18,7 @@ namespace ElectronicsShopDataBaseImplement.Models public string ProductName { get; set; }=string.Empty; [Required] public double Price { get; set; } - [Required] + [ForeignKey("CategoryID")] public int CategoryID { get; set; } public static Product? Create(ProductBindingModel? model) diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs index 3dcdec3..12405c9 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs @@ -4,6 +4,7 @@ using ElectronicsShopDataModels; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -25,7 +26,7 @@ namespace ElectronicsShopDataBaseImplement.Models public string Login { get; set; } = string.Empty; [Required] public string Email { get; set; } = string.Empty; - [Required] + [ForeignKey("RoleID")] public int RoleID { get; set; } public static User? Create(UserBindingModel model)