исправлена связь

This commit is contained in:
VictoriaPresnyakova 2023-06-17 15:16:46 +04:00
parent ca2fcea02d
commit 402f60036d
4 changed files with 26 additions and 12 deletions

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace JewelryStoreDatabaseImplement.Migrations
{
[DbContext(typeof(JewelryStoreDataBase))]
[Migration("20230616194257_init")]
[Migration("20230617111616_init")]
partial class init
{
/// <inheritdoc />
@ -169,12 +169,15 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property<int>("JewelId")
.HasColumnType("int");
b.Property<int>("ManufactureId")
.HasColumnType("int");
b.Property<int>("StoreId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("JewelId");
b.HasIndex("ManufactureId");
b.HasIndex("StoreId");
@ -214,8 +217,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.StoreJewel", b =>
{
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany()
.HasForeignKey("JewelId")
.WithMany("Shops")
.HasForeignKey("ManufactureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -240,6 +243,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Store", b =>

View File

@ -115,14 +115,15 @@ namespace JewelryStoreDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"),
JewelId = table.Column<int>(type: "int", nullable: false),
StoreId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
Count = table.Column<int>(type: "int", nullable: false),
ManufactureId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StoreJewels", x => x.Id);
table.ForeignKey(
name: "FK_StoreJewels_Jewels_JewelId",
column: x => x.JewelId,
name: "FK_StoreJewels_Jewels_ManufactureId",
column: x => x.ManufactureId,
principalTable: "Jewels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
@ -150,9 +151,9 @@ namespace JewelryStoreDatabaseImplement.Migrations
column: "JewelId");
migrationBuilder.CreateIndex(
name: "IX_StoreJewels_JewelId",
name: "IX_StoreJewels_ManufactureId",
table: "StoreJewels",
column: "JewelId");
column: "ManufactureId");
migrationBuilder.CreateIndex(
name: "IX_StoreJewels_StoreId",

View File

@ -166,12 +166,15 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Property<int>("JewelId")
.HasColumnType("int");
b.Property<int>("ManufactureId")
.HasColumnType("int");
b.Property<int>("StoreId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("JewelId");
b.HasIndex("ManufactureId");
b.HasIndex("StoreId");
@ -211,8 +214,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.StoreJewel", b =>
{
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
.WithMany()
.HasForeignKey("JewelId")
.WithMany("Shops")
.HasForeignKey("ManufactureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -237,6 +240,8 @@ namespace JewelryStoreDatabaseImplement.Migrations
b.Navigation("Components");
b.Navigation("Orders");
b.Navigation("Shops");
});
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Store", b =>

View File

@ -42,6 +42,9 @@ namespace JewelryStoreDatabaseImplement.Models
[ForeignKey("JewelId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ManufactureId")]
public virtual List<StoreJewel> Shops { get; set; } = new();
public static Jewel Create(JewelryStoreDataBase context, JewelBindingModel model)
{
return new Jewel()