From 305be555db034488c33ba48ee352d944470bd4ba Mon Sep 17 00:00:00 2001 From: Steve Smith Date: Sun, 18 Aug 2019 15:16:31 -0400 Subject: [PATCH] Updated packages; Using configuration classes for EF Core. --- eShopOnWeb.sln | 6 +- src/ApplicationCore/ApplicationCore.csproj | 2 +- src/Infrastructure/Data/CatalogContext.cs | 136 +--------- .../Data/Config/AddressConfiguration.cs | 31 +++ .../Data/Config/BasketConfiguration.cs | 19 ++ .../Data/Config/BasketItemConfiguration.cs | 16 ++ .../Data/Config/CatalogBrandConfiguration.cs | 22 ++ .../Data/Config/CatalogItemConfiguration.cs | 37 +++ .../Config/CatalogItemOrderedConfiguration.cs | 16 ++ .../Data/Config/CatalogTypeConfiguration.cs | 22 ++ .../Data/Config/OrderConfiguration.cs | 18 ++ .../Data/Config/OrderItemConfiguration.cs | 18 ++ ...90818191507_UpdatedConstraints.Designer.cs | 254 ++++++++++++++++++ .../20190818191507_UpdatedConstraints.cs | 113 ++++++++ .../Migrations/CatalogContextModelSnapshot.cs | 15 +- src/Infrastructure/Infrastructure.csproj | 5 +- src/Web/Startup.cs | 4 +- src/Web/Web.csproj | 4 +- tests/FunctionalTests/FunctionalTests.csproj | 4 +- .../IntegrationTests/IntegrationTests.csproj | 6 +- tests/UnitTests/UnitTests.csproj | 4 +- 21 files changed, 599 insertions(+), 153 deletions(-) create mode 100644 src/Infrastructure/Data/Config/AddressConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/BasketConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/BasketItemConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/CatalogItemConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/CatalogTypeConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/OrderConfiguration.cs create mode 100644 src/Infrastructure/Data/Config/OrderItemConfiguration.cs create mode 100644 src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.Designer.cs create mode 100644 src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.cs diff --git a/eShopOnWeb.sln b/eShopOnWeb.sln index 71ac5fd..768d154 100644 --- a/eShopOnWeb.sln +++ b/eShopOnWeb.sln @@ -1,7 +1,6 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26730.16 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29102.190 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{419A6ACE-0419-4315-A6FB-B0E63D39432E}" EndProject @@ -23,6 +22,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0BD72BEA-EF42-4B72-8B69-12A39EC76FBA}" ProjectSection(SolutionItems) = preProject docker-compose.yml = docker-compose.yml + README.md = README.md EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "src\Web\Web.csproj", "{227CF035-29B0-448D-97E4-944F9EA850E5}" diff --git a/src/ApplicationCore/ApplicationCore.csproj b/src/ApplicationCore/ApplicationCore.csproj index f29ae0a..57861cb 100644 --- a/src/ApplicationCore/ApplicationCore.csproj +++ b/src/ApplicationCore/ApplicationCore.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/Infrastructure/Data/CatalogContext.cs b/src/Infrastructure/Data/CatalogContext.cs index eac0567..98168d0 100644 --- a/src/Infrastructure/Data/CatalogContext.cs +++ b/src/Infrastructure/Data/CatalogContext.cs @@ -1,12 +1,11 @@ -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Ardalis.EFCore.Extensions; +using Microsoft.EntityFrameworkCore; using Microsoft.eShopWeb.ApplicationCore.Entities; using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; namespace Microsoft.eShopWeb.Infrastructure.Data { - public class CatalogContext : DbContext { public CatalogContext(DbContextOptions options) : base(options) @@ -23,134 +22,11 @@ namespace Microsoft.eShopWeb.Infrastructure.Data protected override void OnModelCreating(ModelBuilder builder) { - builder.Entity(ConfigureBasket); - builder.Entity(ConfigureCatalogBrand); - builder.Entity(ConfigureCatalogType); - builder.Entity(ConfigureCatalogItem); - builder.Entity(ConfigureOrder); - builder.Entity(ConfigureOrderItem); - builder.Entity
(ConfigureAddress); - builder.Entity(ConfigureCatalogItemOrdered); - builder.Entity(ConfigureBasketItem); - } + base.OnModelCreating(builder); + builder.ApplyAllConfigurationsFromCurrentAssembly(); - private void ConfigureBasketItem(EntityTypeBuilder builder) - { - builder.Property(bi => bi.UnitPrice) - .IsRequired(true) - .HasColumnType("decimal(18,2)"); - } - - private void ConfigureCatalogItemOrdered(EntityTypeBuilder builder) - { - builder.Property(cio => cio.ProductName) - .HasMaxLength(50) - .IsRequired(); - } - - private void ConfigureAddress(EntityTypeBuilder
builder) - { - builder.Property(a => a.ZipCode) - .HasMaxLength(18) - .IsRequired(); - - builder.Property(a => a.Street) - .HasMaxLength(180) - .IsRequired(); - - builder.Property(a => a.State) - .HasMaxLength(60); - - builder.Property(a => a.Country) - .HasMaxLength(90) - .IsRequired(); - - builder.Property(a => a.City) - .HasMaxLength(100) - .IsRequired(); - } - - private void ConfigureBasket(EntityTypeBuilder builder) - { - var navigation = builder.Metadata.FindNavigation(nameof(Basket.Items)); - - navigation.SetPropertyAccessMode(PropertyAccessMode.Field); - } - - private void ConfigureCatalogItem(EntityTypeBuilder builder) - { - builder.ToTable("Catalog"); - - builder.Property(ci => ci.Id) - .ForSqlServerUseSequenceHiLo("catalog_hilo") - .IsRequired(); - - builder.Property(ci => ci.Name) - .IsRequired(true) - .HasMaxLength(50); - - builder.Property(ci => ci.Price) - .IsRequired(true) - .HasColumnType("decimal(18,2)"); - - builder.Property(ci => ci.PictureUri) - .IsRequired(false); - - builder.HasOne(ci => ci.CatalogBrand) - .WithMany() - .HasForeignKey(ci => ci.CatalogBrandId); - - builder.HasOne(ci => ci.CatalogType) - .WithMany() - .HasForeignKey(ci => ci.CatalogTypeId); - } - - private void ConfigureCatalogBrand(EntityTypeBuilder builder) - { - builder.ToTable("CatalogBrand"); - - builder.HasKey(ci => ci.Id); - - builder.Property(ci => ci.Id) - .ForSqlServerUseSequenceHiLo("catalog_brand_hilo") - .IsRequired(); - - builder.Property(cb => cb.Brand) - .IsRequired() - .HasMaxLength(100); - } - - private void ConfigureCatalogType(EntityTypeBuilder builder) - { - builder.ToTable("CatalogType"); - - builder.HasKey(ci => ci.Id); - - builder.Property(ci => ci.Id) - .ForSqlServerUseSequenceHiLo("catalog_type_hilo") - .IsRequired(); - - builder.Property(cb => cb.Type) - .IsRequired() - .HasMaxLength(100); - } - - private void ConfigureOrder(EntityTypeBuilder builder) - { - var navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems)); - - navigation.SetPropertyAccessMode(PropertyAccessMode.Field); - - builder.OwnsOne(o => o.ShipToAddress); - } - - private void ConfigureOrderItem(EntityTypeBuilder builder) - { - builder.OwnsOne(i => i.ItemOrdered); - - builder.Property(oi => oi.UnitPrice) - .IsRequired(true) - .HasColumnType("decimal(18,2)"); + // alternately this is built-in to EF Core 2.2 + //builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly()); } } } diff --git a/src/Infrastructure/Data/Config/AddressConfiguration.cs b/src/Infrastructure/Data/Config/AddressConfiguration.cs new file mode 100644 index 0000000..ff940bd --- /dev/null +++ b/src/Infrastructure/Data/Config/AddressConfiguration.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class AddressConfiguration : IEntityTypeConfiguration
+ { + public void Configure(EntityTypeBuilder
builder) + { + builder.Property(a => a.ZipCode) + .HasMaxLength(18) + .IsRequired(); + + builder.Property(a => a.Street) + .HasMaxLength(180) + .IsRequired(); + + builder.Property(a => a.State) + .HasMaxLength(60); + + builder.Property(a => a.Country) + .HasMaxLength(90) + .IsRequired(); + + builder.Property(a => a.City) + .HasMaxLength(100) + .IsRequired(); + } + } +} diff --git a/src/Infrastructure/Data/Config/BasketConfiguration.cs b/src/Infrastructure/Data/Config/BasketConfiguration.cs new file mode 100644 index 0000000..c5d681d --- /dev/null +++ b/src/Infrastructure/Data/Config/BasketConfiguration.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class BasketConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + var navigation = builder.Metadata.FindNavigation(nameof(Basket.Items)); + navigation.SetPropertyAccessMode(PropertyAccessMode.Field); + + builder.Property(b => b.BuyerId) + .IsRequired() + .HasMaxLength(20); + } + } +} diff --git a/src/Infrastructure/Data/Config/BasketItemConfiguration.cs b/src/Infrastructure/Data/Config/BasketItemConfiguration.cs new file mode 100644 index 0000000..7d9aba1 --- /dev/null +++ b/src/Infrastructure/Data/Config/BasketItemConfiguration.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class BasketItemConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.Property(bi => bi.UnitPrice) + .IsRequired(true) + .HasColumnType("decimal(18,2)"); + } + } +} diff --git a/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs b/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs new file mode 100644 index 0000000..4fb978a --- /dev/null +++ b/src/Infrastructure/Data/Config/CatalogBrandConfiguration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class CatalogBrandConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(ci => ci.Id); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("catalog_brand_hilo") + .IsRequired(); + + builder.Property(cb => cb.Brand) + .IsRequired() + .HasMaxLength(100); + } + } +} diff --git a/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs new file mode 100644 index 0000000..3a56b42 --- /dev/null +++ b/src/Infrastructure/Data/Config/CatalogItemConfiguration.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class CatalogItemConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.ToTable("Catalog"); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("catalog_hilo") + .IsRequired(); + + builder.Property(ci => ci.Name) + .IsRequired(true) + .HasMaxLength(50); + + builder.Property(ci => ci.Price) + .IsRequired(true) + .HasColumnType("decimal(18,2)"); + + builder.Property(ci => ci.PictureUri) + .IsRequired(false); + + builder.HasOne(ci => ci.CatalogBrand) + .WithMany() + .HasForeignKey(ci => ci.CatalogBrandId); + + builder.HasOne(ci => ci.CatalogType) + .WithMany() + .HasForeignKey(ci => ci.CatalogTypeId); + } + } +} diff --git a/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs new file mode 100644 index 0000000..8a750be --- /dev/null +++ b/src/Infrastructure/Data/Config/CatalogItemOrderedConfiguration.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class CatalogItemOrderedConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.Property(cio => cio.ProductName) + .HasMaxLength(50) + .IsRequired(); + } + } +} diff --git a/src/Infrastructure/Data/Config/CatalogTypeConfiguration.cs b/src/Infrastructure/Data/Config/CatalogTypeConfiguration.cs new file mode 100644 index 0000000..1f465bd --- /dev/null +++ b/src/Infrastructure/Data/Config/CatalogTypeConfiguration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class CatalogTypeConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(ci => ci.Id); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("catalog_type_hilo") + .IsRequired(); + + builder.Property(cb => cb.Type) + .IsRequired() + .HasMaxLength(100); + } + } +} diff --git a/src/Infrastructure/Data/Config/OrderConfiguration.cs b/src/Infrastructure/Data/Config/OrderConfiguration.cs new file mode 100644 index 0000000..3d1ce74 --- /dev/null +++ b/src/Infrastructure/Data/Config/OrderConfiguration.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class OrderConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + var navigation = builder.Metadata.FindNavigation(nameof(Order.OrderItems)); + + navigation.SetPropertyAccessMode(PropertyAccessMode.Field); + + builder.OwnsOne(o => o.ShipToAddress); + } + } +} diff --git a/src/Infrastructure/Data/Config/OrderItemConfiguration.cs b/src/Infrastructure/Data/Config/OrderItemConfiguration.cs new file mode 100644 index 0000000..20b2617 --- /dev/null +++ b/src/Infrastructure/Data/Config/OrderItemConfiguration.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Config +{ + public class OrderItemConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.OwnsOne(i => i.ItemOrdered); + + builder.Property(oi => oi.UnitPrice) + .IsRequired(true) + .HasColumnType("decimal(18,2)"); + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.Designer.cs b/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.Designer.cs new file mode 100644 index 0000000..5efbf3a --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.Designer.cs @@ -0,0 +1,254 @@ +// +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; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + [DbContext(typeof(CatalogContext))] + [Migration("20190818191507_UpdatedConstraints")] + partial class UpdatedConstraints + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("Relational:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId") + .IsRequired() + .HasMaxLength(20); + + b.HasKey("Id"); + + b.ToTable("Baskets"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.BasketItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BasketId"); + + b.Property("CatalogItemId"); + + b.Property("Quantity"); + + 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() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Brand") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogBrands"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("CatalogBrandId"); + + b.Property("CatalogTypeId"); + + b.Property("Description"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50); + + b.Property("PictureUri"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CatalogBrandId"); + + b.HasIndex("CatalogTypeId"); + + b.ToTable("Catalog"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Type") + .IsRequired() + .HasMaxLength(100); + + b.HasKey("Id"); + + b.ToTable("CatalogTypes"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("BuyerId"); + + b.Property("OrderDate"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b.Property("OrderId"); + + b.Property("UnitPrice") + .HasColumnType("decimal(18,2)"); + + b.Property("Units"); + + 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") + .WithMany("Items") + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogBrand", "CatalogBrand") + .WithMany() + .HasForeignKey("CatalogBrandId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogType", "CatalogType") + .WithMany() + .HasForeignKey("CatalogTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => + { + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "ShipToAddress", b1 => + { + b1.Property("OrderId") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("City") + .IsRequired() + .HasMaxLength(100); + + b1.Property("Country") + .IsRequired() + .HasMaxLength(90); + + b1.Property("State") + .HasMaxLength(60); + + b1.Property("Street") + .IsRequired() + .HasMaxLength(180); + + b1.Property("ZipCode") + .IsRequired() + .HasMaxLength(18); + + b1.HasKey("OrderId"); + + b1.ToTable("Orders"); + + b1.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order") + .WithOne("ShipToAddress") + .HasForeignKey("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Address", "OrderId") + .OnDelete(DeleteBehavior.Cascade); + }); + }); + + modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem", b => + { + b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order") + .WithMany("OrderItems") + .HasForeignKey("OrderId"); + + b.OwnsOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "ItemOrdered", b1 => + { + b1.Property("OrderItemId") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + b1.Property("CatalogItemId"); + + b1.Property("PictureUri"); + + b1.Property("ProductName") + .IsRequired() + .HasMaxLength(50); + + b1.HasKey("OrderItemId"); + + b1.ToTable("OrderItems"); + + b1.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.OrderItem") + .WithOne("ItemOrdered") + .HasForeignKey("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.CatalogItemOrdered", "OrderItemId") + .OnDelete(DeleteBehavior.Cascade); + }); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.cs b/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.cs new file mode 100644 index 0000000..9106bd6 --- /dev/null +++ b/src/Infrastructure/Data/Migrations/20190818191507_UpdatedConstraints.cs @@ -0,0 +1,113 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations +{ + public partial class UpdatedConstraints : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "Catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogType", + table: "CatalogType"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogBrand", + table: "CatalogBrand"); + + migrationBuilder.RenameTable( + name: "CatalogType", + newName: "CatalogTypes"); + + migrationBuilder.RenameTable( + name: "CatalogBrand", + newName: "CatalogBrands"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogTypes", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogBrands", + table: "CatalogBrands", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogBrands_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId", + principalTable: "CatalogBrands", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogTypes_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId", + principalTable: "CatalogTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogBrands_CatalogBrandId", + table: "Catalog"); + + migrationBuilder.DropForeignKey( + name: "FK_Catalog_CatalogTypes_CatalogTypeId", + table: "Catalog"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogTypes", + table: "CatalogTypes"); + + migrationBuilder.DropPrimaryKey( + name: "PK_CatalogBrands", + table: "CatalogBrands"); + + migrationBuilder.RenameTable( + name: "CatalogTypes", + newName: "CatalogType"); + + migrationBuilder.RenameTable( + name: "CatalogBrands", + newName: "CatalogBrand"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogType", + table: "CatalogType", + column: "Id"); + + migrationBuilder.AddPrimaryKey( + name: "PK_CatalogBrand", + table: "CatalogBrand", + column: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogBrand_CatalogBrandId", + table: "Catalog", + column: "CatalogBrandId", + principalTable: "CatalogBrand", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Catalog_CatalogType_CatalogTypeId", + table: "Catalog", + column: "CatalogTypeId", + principalTable: "CatalogType", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs index d67608f..7171f46 100644 --- a/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs +++ b/src/Infrastructure/Data/Migrations/CatalogContextModelSnapshot.cs @@ -15,7 +15,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "2.2.3-servicing-35854") + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") .HasAnnotation("Relational:MaxIdentifierLength", 128) .HasAnnotation("Relational:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'") .HasAnnotation("Relational:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'") @@ -28,7 +28,9 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("BuyerId"); + b.Property("BuyerId") + .IsRequired() + .HasMaxLength(20); b.HasKey("Id"); @@ -41,7 +43,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations .ValueGeneratedOnAdd() .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - b.Property("BasketId"); + b.Property("BasketId"); b.Property("CatalogItemId"); @@ -70,7 +72,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.HasKey("Id"); - b.ToTable("CatalogBrand"); + b.ToTable("CatalogBrands"); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => @@ -117,7 +119,7 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations b.HasKey("Id"); - b.ToTable("CatalogType"); + b.ToTable("CatalogTypes"); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.OrderAggregate.Order", b => @@ -159,7 +161,8 @@ namespace Microsoft.eShopWeb.Infrastructure.Data.Migrations { b.HasOne("Microsoft.eShopWeb.ApplicationCore.Entities.BasketAggregate.Basket") .WithMany("Items") - .HasForeignKey("BasketId"); + .HasForeignKey("BasketId") + .OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity("Microsoft.eShopWeb.ApplicationCore.Entities.CatalogItem", b => diff --git a/src/Infrastructure/Infrastructure.csproj b/src/Infrastructure/Infrastructure.csproj index db74180..8c3a4b3 100644 --- a/src/Infrastructure/Infrastructure.csproj +++ b/src/Infrastructure/Infrastructure.csproj @@ -6,10 +6,11 @@ + - - + + diff --git a/src/Web/Startup.cs b/src/Web/Startup.cs index daac6b1..8482694 100644 --- a/src/Web/Startup.cs +++ b/src/Web/Startup.cs @@ -43,10 +43,10 @@ namespace Microsoft.eShopWeb.Web public void ConfigureDevelopmentServices(IServiceCollection services) { // use in-memory database - ConfigureInMemoryDatabases(services); + // ConfigureInMemoryDatabases(services); // use real database - // ConfigureProductionServices(services); + ConfigureProductionServices(services); } private void ConfigureInMemoryDatabases(IServiceCollection services) diff --git a/src/Web/Web.csproj b/src/Web/Web.csproj index 3fccf42..4878c96 100644 --- a/src/Web/Web.csproj +++ b/src/Web/Web.csproj @@ -18,9 +18,9 @@ - + - + diff --git a/tests/FunctionalTests/FunctionalTests.csproj b/tests/FunctionalTests/FunctionalTests.csproj index 6ebd9b8..b6df251 100644 --- a/tests/FunctionalTests/FunctionalTests.csproj +++ b/tests/FunctionalTests/FunctionalTests.csproj @@ -15,13 +15,13 @@ - + all runtime; build; native; contentfiles; analyzers - + diff --git a/tests/IntegrationTests/IntegrationTests.csproj b/tests/IntegrationTests/IntegrationTests.csproj index ce38e73..ee2bf51 100644 --- a/tests/IntegrationTests/IntegrationTests.csproj +++ b/tests/IntegrationTests/IntegrationTests.csproj @@ -7,9 +7,9 @@ - - - + + + all diff --git a/tests/UnitTests/UnitTests.csproj b/tests/UnitTests/UnitTests.csproj index 5a28914..17671db 100644 --- a/tests/UnitTests/UnitTests.csproj +++ b/tests/UnitTests/UnitTests.csproj @@ -8,8 +8,8 @@ - - + + all