From 48e52db40eb97d2499f1bd6a84d7f70c77b0dc22 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 30 Apr 2024 23:03:49 +0400 Subject: [PATCH 1/2] 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; From 6ae8e7b62ceeff2cdad37842669b0427c7fa3293 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Tue, 30 Apr 2024 23:14:08 +0400 Subject: [PATCH 2/2] Update migration --- .../20240430190807_ForeignKey-fix.Designer.cs | 524 ++++++++++++++++++ .../20240430190807_ForeignKey-fix.cs | 128 +++++ .../ComputerShopDatabaseModelSnapshot.cs | 29 +- .../Models/Assembly.cs | 4 +- 4 files changed, 671 insertions(+), 14 deletions(-) create mode 100644 ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.Designer.cs create mode 100644 ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.cs diff --git a/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.Designer.cs b/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.Designer.cs new file mode 100644 index 0000000..52be0db --- /dev/null +++ b/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.Designer.cs @@ -0,0 +1,524 @@ +// +using System; +using ComputerShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerShopDatabase))] + [Migration("20240430190807_ForeignKey-fix")] + partial class ForeignKeyfix + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AssemblyName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Category") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Assemblies"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("ComponentId"); + + b.ToTable("AssemblyComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("ProductName") + .IsRequired() + .HasColumnType("text"); + + b.Property("ShipmentId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("Warranty") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ShipmentId"); + + b.HasIndex("UserId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ProductComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AssemblyId") + .HasColumnType("integer"); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("DateRequest") + .HasColumnType("timestamp without time zone"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("AssemblyId"); + + b.HasIndex("UserId"); + + b.ToTable("Requests"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.RequestOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("RequestId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("RequestId"); + + b.ToTable("RequestOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateShipment") + .HasColumnType("timestamp without time zone"); + + b.Property("ProviderName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Shipments"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ShipmentOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("ShipmentId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ShipmentId"); + + b.ToTable("ShipmentOrders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.User", null) + .WithMany("Assemblies") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.AssemblyComponent", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Components") + .HasForeignKey("AssemblyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("AssemblyComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.User", null) + .WithMany("Components") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.User", null) + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", "Shipment") + .WithMany("Products") + .HasForeignKey("ShipmentId"); + + b.HasOne("ComputerShopDatabaseImplement.Models.User", null) + .WithMany("Proucts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Shipment"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("ProductComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") + .WithMany("Requests") + .HasForeignKey("AssemblyId"); + + b.HasOne("ComputerShopDatabaseImplement.Models.User", "User") + .WithMany("Requests") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Assembly"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.RequestOrder", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("Requests") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Request", "Request") + .WithMany("Orders") + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Request"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.User", "User") + .WithMany("Shipments") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ShipmentOrder", b => + { + b.HasOne("ComputerShopDatabaseImplement.Models.Order", "Order") + .WithMany("Shipments") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", "Shipment") + .WithMany("Orders") + .HasForeignKey("ShipmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Shipment"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => + { + b.Navigation("Components"); + + b.Navigation("Requests"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => + { + b.Navigation("AssemblyComponents"); + + b.Navigation("ProductComponents"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => + { + b.Navigation("Requests"); + + b.Navigation("Shipments"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Shipment", b => + { + b.Navigation("Orders"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerShopDatabaseImplement.Models.User", b => + { + b.Navigation("Assemblies"); + + b.Navigation("Components"); + + b.Navigation("Orders"); + + b.Navigation("Proucts"); + + b.Navigation("Requests"); + + b.Navigation("Shipments"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.cs b/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.cs new file mode 100644 index 0000000..ef48753 --- /dev/null +++ b/ComputerShopDatabaseImplement/Migrations/20240430190807_ForeignKey-fix.cs @@ -0,0 +1,128 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerShopDatabaseImplement.Migrations +{ + /// + public partial class ForeignKeyfix : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AssemblyComponents_Assemblies_ComponentId", + table: "AssemblyComponents"); + + migrationBuilder.DropForeignKey( + name: "FK_ProductComponents_Components_ComponentId1", + table: "ProductComponents"); + + migrationBuilder.DropForeignKey( + name: "FK_ProductComponents_Products_ComponentId", + table: "ProductComponents"); + + migrationBuilder.DropIndex( + name: "IX_ProductComponents_ComponentId1", + table: "ProductComponents"); + + migrationBuilder.DropColumn( + name: "ComponentId1", + table: "ProductComponents"); + + migrationBuilder.CreateIndex( + name: "IX_ProductComponents_ProductId", + table: "ProductComponents", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_AssemblyComponents_AssemblyId", + table: "AssemblyComponents", + column: "AssemblyId"); + + migrationBuilder.AddForeignKey( + name: "FK_AssemblyComponents_Assemblies_AssemblyId", + table: "AssemblyComponents", + column: "AssemblyId", + principalTable: "Assemblies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ProductComponents_Components_ComponentId", + table: "ProductComponents", + column: "ComponentId", + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ProductComponents_Products_ProductId", + table: "ProductComponents", + column: "ProductId", + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AssemblyComponents_Assemblies_AssemblyId", + table: "AssemblyComponents"); + + migrationBuilder.DropForeignKey( + name: "FK_ProductComponents_Components_ComponentId", + table: "ProductComponents"); + + migrationBuilder.DropForeignKey( + name: "FK_ProductComponents_Products_ProductId", + table: "ProductComponents"); + + migrationBuilder.DropIndex( + name: "IX_ProductComponents_ProductId", + table: "ProductComponents"); + + migrationBuilder.DropIndex( + name: "IX_AssemblyComponents_AssemblyId", + table: "AssemblyComponents"); + + migrationBuilder.AddColumn( + name: "ComponentId1", + table: "ProductComponents", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateIndex( + name: "IX_ProductComponents_ComponentId1", + table: "ProductComponents", + column: "ComponentId1"); + + migrationBuilder.AddForeignKey( + name: "FK_AssemblyComponents_Assemblies_ComponentId", + table: "AssemblyComponents", + column: "ComponentId", + principalTable: "Assemblies", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ProductComponents_Components_ComponentId1", + table: "ProductComponents", + column: "ComponentId1", + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_ProductComponents_Products_ComponentId", + table: "ProductComponents", + column: "ComponentId", + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs b/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs index 009af65..fc83080 100644 --- a/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs +++ b/ComputerShopDatabaseImplement/Migrations/ComputerShopDatabaseModelSnapshot.cs @@ -70,6 +70,8 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("AssemblyId"); + b.HasIndex("ComponentId"); b.ToTable("AssemblyComponents"); @@ -171,9 +173,6 @@ namespace ComputerShopDatabaseImplement.Migrations b.Property("ComponentId") .HasColumnType("integer"); - b.Property("ComponentId1") - .HasColumnType("integer"); - b.Property("Count") .HasColumnType("integer"); @@ -184,7 +183,7 @@ namespace ComputerShopDatabaseImplement.Migrations b.HasIndex("ComponentId"); - b.HasIndex("ComponentId1"); + b.HasIndex("ProductId"); b.ToTable("ProductComponents"); }); @@ -331,7 +330,7 @@ namespace ComputerShopDatabaseImplement.Migrations { b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") .WithMany("Components") - .HasForeignKey("ComponentId") + .HasForeignKey("AssemblyId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -366,7 +365,7 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Product", b => { - b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", null) + b.HasOne("ComputerShopDatabaseImplement.Models.Shipment", "Shipment") .WithMany("Products") .HasForeignKey("ShipmentId"); @@ -375,19 +374,21 @@ namespace ComputerShopDatabaseImplement.Migrations .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Shipment"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.ProductComponent", b => { - b.HasOne("ComputerShopDatabaseImplement.Models.Product", "Product") - .WithMany("Components") + b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") + .WithMany("ProductComponents") .HasForeignKey("ComponentId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("ComputerShopDatabaseImplement.Models.Component", "Component") - .WithMany() - .HasForeignKey("ComponentId1") + b.HasOne("ComputerShopDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -399,7 +400,7 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Request", b => { b.HasOne("ComputerShopDatabaseImplement.Models.Assembly", "Assembly") - .WithMany() + .WithMany("Requests") .HasForeignKey("AssemblyId"); b.HasOne("ComputerShopDatabaseImplement.Models.User", "User") @@ -465,11 +466,15 @@ namespace ComputerShopDatabaseImplement.Migrations modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Assembly", b => { b.Navigation("Components"); + + b.Navigation("Requests"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Component", b => { b.Navigation("AssemblyComponents"); + + b.Navigation("ProductComponents"); }); modelBuilder.Entity("ComputerShopDatabaseImplement.Models.Order", b => diff --git a/ComputerShopDatabaseImplement/Models/Assembly.cs b/ComputerShopDatabaseImplement/Models/Assembly.cs index fa1548b..e0df13e 100644 --- a/ComputerShopDatabaseImplement/Models/Assembly.cs +++ b/ComputerShopDatabaseImplement/Models/Assembly.cs @@ -22,10 +22,10 @@ namespace ComputerShopDatabaseImplement.Models public string Category { get; private set; } = string.Empty; [ForeignKey("AssemblyId")] - public virtual List Components { get; set; } = new(); + public virtual List Requests { get; set; } = new(); [ForeignKey("AssemblyId")] - public virtual List Requests { get; set; } = new(); + public virtual List Components { get; set; } = new(); private Dictionary? _assemblyComponents;