From c037227b55fb2187402648bf9dc4148c4b1e2544 Mon Sep 17 00:00:00 2001 From: yigith Date: Fri, 21 Jan 2022 18:15:03 +0300 Subject: [PATCH] Fixing issue 656 (#657) --- .../Data/Config/OrderConfiguration.cs | 2 + ...0211231093753_FixShipToAddress.Designer.cs | 315 ++++++++++++++++++ .../20211231093753_FixShipToAddress.cs | 103 ++++++ .../Migrations/CatalogContextModelSnapshot.cs | 60 ++-- 4 files changed, 452 insertions(+), 28 deletions(-) create mode 100644 src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.Designer.cs create mode 100644 src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.cs diff --git a/src/Infrastructure/Data/Config/OrderConfiguration.cs b/src/Infrastructure/Data/Config/OrderConfiguration.cs index 735e914..3b5a8c3 100644 --- a/src/Infrastructure/Data/Config/OrderConfiguration.cs +++ b/src/Infrastructure/Data/Config/OrderConfiguration.cs @@ -39,5 +39,7 @@ public class OrderConfiguration : IEntityTypeConfiguration .HasMaxLength(100) .IsRequired(); }); + + builder.Navigation(x => x.ShipToAddress).IsRequired(); } } diff --git a/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.Designer.cs b/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.Designer.cs new file mode 100644 index 0000000..16e966e --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.Designer.cs @@ -0,0 +1,315 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Microsoft.eShopWeb.Infrastructure.Data; + +#nullable disable + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20211231093753_FixShipToAddress")] + partial class FixShipToAddress + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); + + modelBuilder.HasSequence("catalog_brand_hilo") + .IncrementsBy(10); + + modelBuilder.HasSequence("catalog_hilo") + .IncrementsBy(10); + + modelBuilder.HasSequence("catalog_type_hilo") + .IncrementsBy(10); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("BuyerId") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("BasketId") + .HasColumnType("int"); + + b.Property("CatalogItemId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("BasketId"); + + b.ToTable("BasketItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_brand_hilo"); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("CatalogBrands"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_hilo"); + + b.Property("CatalogBrandId") + .HasColumnType("int"); + + b.Property("CatalogTypeId") + .HasColumnType("int"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog", (string)null); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_type_hilo"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("CatalogTypes"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("BuyerId") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("nvarchar(256)"); + + b.Property("OrderDate") + .HasColumnType("datetimeoffset"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.Property("Units") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", null) + .WithMany("Items") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CatalogBrand"); + + b.Navigation("CatalogType"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 => + { + b1.Property("OrderId") + .HasColumnType("int"); + + b1.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b1.Property("Country") + .IsRequired() + .HasMaxLength(90) + .HasColumnType("nvarchar(90)"); + + b1.Property("State") + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b1.Property("Street") + .IsRequired() + .HasMaxLength(180) + .HasColumnType("nvarchar(180)"); + + b1.Property("ZipCode") + .IsRequired() + .HasMaxLength(18) + .HasColumnType("nvarchar(18)"); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.WithOwner() + .HasForeignKey("OrderId"); + }); + + b.Navigation("ShipToAddress") + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", null) + .WithMany("OrderItems") + .HasForeignKey("OrderId"); + + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 => + { + b1.Property("OrderItemId") + .HasColumnType("int"); + + b1.Property("CatalogItemId") + .HasColumnType("int"); + + b1.Property("PictureUri") + .HasColumnType("nvarchar(max)"); + + b1.Property("ProductName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b1.HasKey("OrderItemId"); + + b1.ToTable("OrderItems"); + + b1.WithOwner() + .HasForeignKey("OrderItemId"); + }); + + b.Navigation("ItemOrdered"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", b => + { + b.Navigation("Items"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.Navigation("OrderItems"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.cs b/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.cs new file mode 100644 index 0000000..cc52348 --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20211231093753_FixShipToAddress.cs @@ -0,0 +1,103 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + public partial class FixShipToAddress : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + type: "nvarchar(18)", + maxLength: 18, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(18)", + oldMaxLength: 18, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + type: "nvarchar(180)", + maxLength: 180, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(180)", + oldMaxLength: 180, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + type: "nvarchar(90)", + maxLength: 90, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(90)", + oldMaxLength: 90, + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + type: "nvarchar(100)", + maxLength: 100, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "nvarchar(100)", + oldMaxLength: 100, + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ShipToAddress_ZipCode", + table: "Orders", + type: "nvarchar(18)", + maxLength: 18, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(18)", + oldMaxLength: 18); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Street", + table: "Orders", + type: "nvarchar(180)", + maxLength: 180, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(180)", + oldMaxLength: 180); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_Country", + table: "Orders", + type: "nvarchar(90)", + maxLength: 90, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(90)", + oldMaxLength: 90); + + migrationBuilder.AlterColumn( + name: "ShipToAddress_City", + table: "Orders", + type: "nvarchar(100)", + maxLength: 100, + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(100)", + oldMaxLength: 100); + } + } +} diff --git a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index acd8ff3..81b8c3e 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -6,6 +6,8 @@ using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.eShopWeb.Infrastructure.Data; +#nullable disable + namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { [DbContext(typeof(CatalogContext))] @@ -15,9 +17,10 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.11") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "6.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1); modelBuilder.HasSequence("catalog_brand_hilo") .IncrementsBy(10); @@ -32,8 +35,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("BuyerId") .IsRequired() @@ -49,8 +53,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("BasketId") .HasColumnType("int"); @@ -75,9 +80,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_brand_hilo"); b.Property("Brand") .IsRequired() @@ -93,9 +98,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_hilo"); b.Property("CatalogBrandId") .HasColumnType("int"); @@ -123,16 +128,16 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.HasIndex("CatalogTypeId"); - b.ToTable("Catalog"); + b.ToTable("Catalog", (string)null); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseHiLo(b.Property("Id"), "catalog_type_hilo"); b.Property("Type") .IsRequired() @@ -148,8 +153,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("BuyerId") .IsRequired() @@ -168,8 +174,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"), 1L, 1); b.Property("OrderId") .HasColumnType("int"); @@ -220,9 +227,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 => { b1.Property("OrderId") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b1.Property("City") .IsRequired() @@ -256,7 +261,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations .HasForeignKey("OrderId"); }); - b.Navigation("ShipToAddress"); + b.Navigation("ShipToAddress") + .IsRequired(); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => @@ -268,9 +274,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 => { b1.Property("OrderItemId") - .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); b1.Property("CatalogItemId") .HasColumnType("int");