From 8682259cfb3a99e13071a88fd690f11fd1362043 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Thu, 18 May 2023 02:56:09 +0400 Subject: [PATCH 1/2] BD fixes. --- .../Implements/PCStorage.cs | 19 +- ...20230517185025_RelationFixesV2.Designer.cs | 499 ------------------ .../20230517185025_RelationFixesV2.cs | 59 --- ...20230517185727_RelationFixesV3.Designer.cs | 498 ----------------- .../20230517185727_RelationFixesV3.cs | 22 - .../ComputerStoreDatabaseModelSnapshot.cs | 33 +- ComputerStoreDatabaseImplement/Models/PC.cs | 36 +- .../Models/Request.cs | 3 + .../Models/RequestComponent.cs | 8 +- 9 files changed, 45 insertions(+), 1132 deletions(-) delete mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.Designer.cs delete mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.cs delete mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.Designer.cs delete mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.cs diff --git a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs index 16c1ec9..68a6e58 100644 --- a/ComputerStoreDatabaseImplement/Implements/PCStorage.cs +++ b/ComputerStoreDatabaseImplement/Implements/PCStorage.cs @@ -20,7 +20,7 @@ namespace ComputerStoreDatabaseImplement.Implements if (string.IsNullOrEmpty(model.Name) && !model.ID.HasValue) { return null; } using var context = new ComputerStoreDatabase(); - return context.PCs.Include(x => x.Employee).Include(x => x.Components).ThenInclude(x => x.Component).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; + return context.PCS.Include(x => x.Employee).Include(x => x.Request).FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && model.Name.Equals(x.Name)) || (model.ID.HasValue && model.ID == x.ID))?.GetViewModel; } @@ -36,13 +36,13 @@ namespace ComputerStoreDatabaseImplement.Implements { return context.PCs.Include(x => x.Employee).Where(x => x.EmployeeID == model.EmployeeID).Select(x => x.GetViewModel).ToList(); } - return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).Where(p => context.Requests.Where(r => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(r.OrderID)).Select(r => r.ID).Contains(p.RequestID)).ToList().Select(x => x.GetViewModel).ToList(); + return context.PCS.Include(x => x.Employee).Include(x => x.Request).Where(p => context.Requests.Where(r => context.Orders.Where(o => o.DateCreate >= model.DateFrom && o.DateCreate <= model.DateTo).Select(o => o.ID).Contains(r.OrderID)).Select(r => r.ID).Contains(p.RequestID)).ToList().Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new ComputerStoreDatabase(); - return context.PCs.Include(x => x.Components).ThenInclude(x => x.Component).ToList().Select(x => x.GetViewModel).ToList(); + return context.PCS.Include(x => x.Employee).Include(x => x.Request).ToList().Select(x => x.GetViewModel).ToList(); } public PCViewModel? Insert(PCBindingModel model) @@ -51,8 +51,17 @@ namespace ComputerStoreDatabaseImplement.Implements var newPC = PC.Create(context, model); if(newPC == null) { return null; } - context.PCs.Add(newPC); + context.PCS.Add(newPC); + + + context.SaveChanges(); + + + + var pc = context.PCS.FirstOrDefault(x => x.Name.Equals(model.Name)); + PC.EnterPCID(context, pc); + return newPC.GetViewModel; } @@ -81,7 +90,7 @@ namespace ComputerStoreDatabaseImplement.Implements public PCViewModel? Delete(PCBindingModel model) { using var context = new ComputerStoreDatabase(); - var specPC = context.PCs.Include(x => x.Components).FirstOrDefault(x => x.ID == model.ID); + var specPC = context.PCS.Include(x => x.Request).FirstOrDefault(x => x.ID == model.ID); if(specPC == null) { return null;} context.PCs.Remove(specPC); context.SaveChanges(); diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.Designer.cs deleted file mode 100644 index 21ee431..0000000 --- a/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.Designer.cs +++ /dev/null @@ -1,499 +0,0 @@ -// -using System; -using ComputerStoreDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace ComputerStoreDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputerStoreDatabase))] - [Migration("20230517185025_RelationFixesV2")] - partial class RelationFixesV2 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("OrderID") - .HasColumnType("int"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("OrderID"); - - b.HasIndex("ProductID"); - - b.ToTable("Consignments"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ConsignmentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ConsignmentID"); - - b.HasIndex("ProductID"); - - b.ToTable("ConsignmentProducts"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("ID"); - - b.ToTable("Employees"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("SellerID") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("SellerID"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("EmployeeID") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("RequestID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("EmployeeID"); - - b.ToTable("PCs"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("EmployeeID") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.HasIndex("EmployeeID"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ComponentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ComponentID"); - - b.HasIndex("ProductID"); - - b.ToTable("ProductComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("OrderID") - .HasColumnType("int"); - - b.Property("PCID") - .HasColumnType("int"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.HasIndex("OrderID"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ComponentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PCID") - .IsRequired() - .HasColumnType("int"); - - b.Property("RequestID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ComponentID"); - - b.HasIndex("PCID"); - - b.HasIndex("RequestID"); - - b.ToTable("RequestComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("ID"); - - b.ToTable("Sellers"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") - .WithMany("_consignments") - .HasForeignKey("OrderID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) - .WithMany("Consignments") - .HasForeignKey("ProductID"); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") - .WithMany("Products") - .HasForeignKey("ConsignmentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consignment"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") - .WithMany("Orders") - .HasForeignKey("SellerID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Seller"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") - .WithMany("PCs") - .HasForeignKey("EmployeeID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Employee"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") - .WithMany("Products") - .HasForeignKey("EmployeeID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Employee"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") - .WithMany("ConsignmentComponents") - .HasForeignKey("ComponentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") - .WithMany("Components") - .HasForeignKey("ProductID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") - .WithMany("_requests") - .HasForeignKey("OrderID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") - .WithMany("RequestComponents") - .HasForeignKey("ComponentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") - .WithMany("Components") - .HasForeignKey("PCID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") - .WithMany("PCs") - .HasForeignKey("RequestID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("PC"); - - b.Navigation("Request"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => - { - b.Navigation("ConsignmentComponents"); - - b.Navigation("RequestComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => - { - b.Navigation("PCs"); - - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.Navigation("_consignments"); - - b.Navigation("_requests"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.Navigation("Components"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.Navigation("Components"); - - b.Navigation("Consignments"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.Navigation("PCs"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => - { - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.cs b/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.cs deleted file mode 100644 index d5c4f95..0000000 --- a/ComputerStoreDatabaseImplement/Migrations/20230517185025_RelationFixesV2.cs +++ /dev/null @@ -1,59 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputerStoreDatabaseImplement.Migrations -{ - /// - public partial class RelationFixesV2 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_RequestComponents_PCs_PCID", - table: "RequestComponents"); - - migrationBuilder.AlterColumn( - name: "PCID", - table: "RequestComponents", - type: "int", - nullable: false, - defaultValue: 0, - oldClrType: typeof(int), - oldType: "int", - oldNullable: true); - - migrationBuilder.AddForeignKey( - name: "FK_RequestComponents_PCs_PCID", - table: "RequestComponents", - column: "PCID", - principalTable: "PCs", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_RequestComponents_PCs_PCID", - table: "RequestComponents"); - - migrationBuilder.AlterColumn( - name: "PCID", - table: "RequestComponents", - type: "int", - nullable: true, - oldClrType: typeof(int), - oldType: "int"); - - migrationBuilder.AddForeignKey( - name: "FK_RequestComponents_PCs_PCID", - table: "RequestComponents", - column: "PCID", - principalTable: "PCs", - principalColumn: "ID"); - } - } -} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.Designer.cs deleted file mode 100644 index 0b67f1f..0000000 --- a/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.Designer.cs +++ /dev/null @@ -1,498 +0,0 @@ -// -using System; -using ComputerStoreDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace ComputerStoreDatabaseImplement.Migrations -{ - [DbContext(typeof(ComputerStoreDatabase))] - [Migration("20230517185727_RelationFixesV3")] - partial class RelationFixesV3 - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("OrderID") - .HasColumnType("int"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("OrderID"); - - b.HasIndex("ProductID"); - - b.ToTable("Consignments"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ConsignmentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ConsignmentID"); - - b.HasIndex("ProductID"); - - b.ToTable("ConsignmentProducts"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("ID"); - - b.ToTable("Employees"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("SellerID") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("SellerID"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("EmployeeID") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.Property("RequestID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("EmployeeID"); - - b.ToTable("PCs"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("EmployeeID") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.HasIndex("EmployeeID"); - - b.ToTable("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ComponentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ProductID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ComponentID"); - - b.HasIndex("ProductID"); - - b.ToTable("ProductComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("OrderID") - .HasColumnType("int"); - - b.Property("PCID") - .HasColumnType("int"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("ID"); - - b.HasIndex("OrderID"); - - b.ToTable("Requests"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("ComponentID") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("PCID") - .HasColumnType("int"); - - b.Property("RequestID") - .HasColumnType("int"); - - b.HasKey("ID"); - - b.HasIndex("ComponentID"); - - b.HasIndex("PCID"); - - b.HasIndex("RequestID"); - - b.ToTable("RequestComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => - { - b.Property("ID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("MiddleName") - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Username") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("ID"); - - b.ToTable("Sellers"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") - .WithMany("_consignments") - .HasForeignKey("OrderID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) - .WithMany("Consignments") - .HasForeignKey("ProductID"); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") - .WithMany("Products") - .HasForeignKey("ConsignmentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") - .WithMany() - .HasForeignKey("ProductID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Consignment"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") - .WithMany("Orders") - .HasForeignKey("SellerID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Seller"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") - .WithMany("PCs") - .HasForeignKey("EmployeeID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Employee"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") - .WithMany("Products") - .HasForeignKey("EmployeeID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Employee"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") - .WithMany("ConsignmentComponents") - .HasForeignKey("ComponentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") - .WithMany("Components") - .HasForeignKey("ProductID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Product"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") - .WithMany("_requests") - .HasForeignKey("OrderID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Order"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => - { - b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") - .WithMany("RequestComponents") - .HasForeignKey("ComponentID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") - .WithMany("Components") - .HasForeignKey("PCID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") - .WithMany("PCs") - .HasForeignKey("RequestID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("PC"); - - b.Navigation("Request"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => - { - b.Navigation("ConsignmentComponents"); - - b.Navigation("RequestComponents"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => - { - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => - { - b.Navigation("PCs"); - - b.Navigation("Products"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => - { - b.Navigation("_consignments"); - - b.Navigation("_requests"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.Navigation("Components"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => - { - b.Navigation("Components"); - - b.Navigation("Consignments"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => - { - b.Navigation("PCs"); - }); - - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => - { - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.cs b/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.cs deleted file mode 100644 index fda75e8..0000000 --- a/ComputerStoreDatabaseImplement/Migrations/20230517185727_RelationFixesV3.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ComputerStoreDatabaseImplement.Migrations -{ - /// - public partial class RelationFixesV3 : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - - } - } -} diff --git a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs index b116199..af60199 100644 --- a/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs +++ b/ComputerStoreDatabaseImplement/Migrations/ComputerStoreDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace ComputerStoreDatabaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("ProductVersion", "7.0.5") .HasAnnotation("Relational:MaxIdentifierLength", 128); SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); @@ -179,7 +179,9 @@ namespace ComputerStoreDatabaseImplement.Migrations b.HasIndex("EmployeeID"); - b.ToTable("PCs"); + b.HasIndex("RequestID"); + + b.ToTable("PCS"); }); modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => @@ -271,7 +273,7 @@ namespace ComputerStoreDatabaseImplement.Migrations b.Property("Count") .HasColumnType("int"); - b.Property("PCID") + b.Property("PCID") .HasColumnType("int"); b.Property("RequestID") @@ -281,8 +283,6 @@ namespace ComputerStoreDatabaseImplement.Migrations b.HasIndex("ComponentID"); - b.HasIndex("PCID"); - b.HasIndex("RequestID"); b.ToTable("RequestComponents"); @@ -371,7 +371,15 @@ namespace ComputerStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PersonalComputers") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.Navigation("Employee"); + + b.Navigation("Request"); }); modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => @@ -423,12 +431,6 @@ namespace ComputerStoreDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC") - .WithMany("Components") - .HasForeignKey("PCID") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") .WithMany("PCs") .HasForeignKey("RequestID") @@ -437,8 +439,6 @@ namespace ComputerStoreDatabaseImplement.Migrations b.Navigation("Component"); - b.Navigation("PC"); - b.Navigation("Request"); }); @@ -468,11 +468,6 @@ namespace ComputerStoreDatabaseImplement.Migrations b.Navigation("_requests"); }); - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => - { - b.Navigation("Components"); - }); - modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => { b.Navigation("Components"); @@ -483,6 +478,8 @@ namespace ComputerStoreDatabaseImplement.Migrations modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => { b.Navigation("PCs"); + + b.Navigation("PersonalComputers"); }); modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => diff --git a/ComputerStoreDatabaseImplement/Models/PC.cs b/ComputerStoreDatabaseImplement/Models/PC.cs index 93dd12e..4e0edfd 100644 --- a/ComputerStoreDatabaseImplement/Models/PC.cs +++ b/ComputerStoreDatabaseImplement/Models/PC.cs @@ -25,29 +25,16 @@ namespace ComputerStoreDatabaseImplement.Models public int EmployeeID { get; private set; } [Required] - public int RequestID { get; private set; } - - private Dictionary? _pcComponents = null; - + public int RequestID { get; private set; } [NotMapped] - public Dictionary PCComponents - { - get - { - if(_pcComponents == null) - { - _pcComponents = Components.ToDictionary(recPC => recPC.ComponentID, recPC => (recPC.Component as IComponentModel, recPC.Count)); - } - return _pcComponents; - } - } - - [ForeignKey("PCID")] - public virtual List? Components { get; set; } = new(); - + public Dictionary PCComponents { get; private set; } = new(); + + public virtual Employee Employee { get; set; } + public virtual Request Request { get; set; } + public static PC Create(ComputerStoreDatabase context, PCBindingModel model) { return new PC() @@ -57,11 +44,7 @@ namespace ComputerStoreDatabaseImplement.Models Price = model.Price, EmployeeID = model.EmployeeID, RequestID = model.RequestID, - Components = model.PCComponents.Select(x => new RequestComponent - { - Component = context.Components.First(y => y.ID == x.Key), - Count = x.Value.Item2 - }).ToList() + PCComponents = model.PCComponents }; } @@ -69,6 +52,7 @@ namespace ComputerStoreDatabaseImplement.Models { Name = model.Name; Price = model.Price; + PCComponents = model.PCComponents; } public PCViewModel GetViewModel => new() @@ -101,19 +85,17 @@ namespace ComputerStoreDatabaseImplement.Models context.SaveChanges(); } - var pc = context.PCs.First(rec => model.ID == ID); foreach(var pcc in model.PCComponents ) { context.RequestComponents.Add(new RequestComponent { - PC = pc, Component = context.Components.First(x=> x.ID == pcc.Key), Request = context.Requests.First(x => x.ID == model.RequestID), Count = pcc.Value.Item2 }); context.SaveChanges(); } - _pcComponents = null; + } } diff --git a/ComputerStoreDatabaseImplement/Models/Request.cs b/ComputerStoreDatabaseImplement/Models/Request.cs index 7db9bc3..58ee0cc 100644 --- a/ComputerStoreDatabaseImplement/Models/Request.cs +++ b/ComputerStoreDatabaseImplement/Models/Request.cs @@ -31,6 +31,9 @@ namespace ComputerStoreDatabaseImplement.Models [ForeignKey("RequestID")] public virtual List PCs { get; set; } = new(); + [ForeignKey("RequestID")] + public virtual List PersonalComputers { get; set; } = new(); + public static Request? Create(ComputerStoreDatabase context, RequestBindingModel model) { if (model == null) diff --git a/ComputerStoreDatabaseImplement/Models/RequestComponent.cs b/ComputerStoreDatabaseImplement/Models/RequestComponent.cs index d05348f..c43b6ac 100644 --- a/ComputerStoreDatabaseImplement/Models/RequestComponent.cs +++ b/ComputerStoreDatabaseImplement/Models/RequestComponent.cs @@ -18,13 +18,13 @@ namespace ComputerStoreDatabaseImplement.Models public int ComponentID { get; set; } - public int PCID { get; set; } + public int? PCID { get; set; } [Required] public int Count { get; set; } - public virtual PC? PC { get; set; } = new(); - public virtual Component Component { get; set; } = new(); - public virtual Request Request { get; set; } = new(); + + public virtual Component Component { get; set; } + public virtual Request Request { get; set; } } } From 391a54d2003630652667c05ef0bbc02797727c96 Mon Sep 17 00:00:00 2001 From: Yuee Shiness Date: Thu, 18 May 2023 02:57:47 +0400 Subject: [PATCH 2/2] Migration --- ...0230517211626_RelationsFixesV7.Designer.cs | 495 ++++++++++++++++++ .../20230517211626_RelationsFixesV7.cs | 38 ++ 2 files changed, 533 insertions(+) create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.Designer.cs create mode 100644 ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.cs diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.Designer.cs b/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.Designer.cs new file mode 100644 index 0000000..c15fe1b --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.Designer.cs @@ -0,0 +1,495 @@ +// +using System; +using ComputerStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerStoreDatabase))] + [Migration("20230517211626_RelationsFixesV7")] + partial class RelationsFixesV7 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.HasIndex("ProductID"); + + b.ToTable("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ConsignmentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ConsignmentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ConsignmentProducts"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("SellerID") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("SellerID"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.HasIndex("RequestID"); + + b.ToTable("PCS"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("EmployeeID") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("EmployeeID"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ProductID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("ProductID"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("OrderID") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("ID"); + + b.HasIndex("OrderID"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("ComponentID") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("PCID") + .HasColumnType("int"); + + b.Property("RequestID") + .HasColumnType("int"); + + b.HasKey("ID"); + + b.HasIndex("ComponentID"); + + b.HasIndex("RequestID"); + + b.ToTable("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Property("ID") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("ID")); + + b.Property("FirstName") + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .HasColumnType("nvarchar(max)"); + + b.Property("MiddleName") + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Username") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ID"); + + b.ToTable("Sellers"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_consignments") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null) + .WithMany("Consignments") + .HasForeignKey("ProductID"); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment") + .WithMany("Products") + .HasForeignKey("ConsignmentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consignment"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller") + .WithMany("Orders") + .HasForeignKey("SellerID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Seller"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("PCs") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PersonalComputers") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee") + .WithMany("Products") + .HasForeignKey("EmployeeID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("ConsignmentComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order") + .WithMany("_requests") + .HasForeignKey("OrderID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b => + { + b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component") + .WithMany("RequestComponents") + .HasForeignKey("ComponentID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request") + .WithMany("PCs") + .HasForeignKey("RequestID") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("ConsignmentComponents"); + + b.Navigation("RequestComponents"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b => + { + b.Navigation("PCs"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b => + { + b.Navigation("_consignments"); + + b.Navigation("_requests"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + + b.Navigation("Consignments"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b => + { + b.Navigation("PCs"); + + b.Navigation("PersonalComputers"); + }); + + modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b => + { + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.cs b/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.cs new file mode 100644 index 0000000..9354abd --- /dev/null +++ b/ComputerStoreDatabaseImplement/Migrations/20230517211626_RelationsFixesV7.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerStoreDatabaseImplement.Migrations +{ + /// + public partial class RelationsFixesV7 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_RequestComponents_PCS_PCID", + table: "RequestComponents"); + + migrationBuilder.DropIndex( + name: "IX_RequestComponents_PCID", + table: "RequestComponents"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateIndex( + name: "IX_RequestComponents_PCID", + table: "RequestComponents", + column: "PCID"); + + migrationBuilder.AddForeignKey( + name: "FK_RequestComponents_PCS_PCID", + table: "RequestComponents", + column: "PCID", + principalTable: "PCS", + principalColumn: "ID"); + } + } +}