From a88fbf339fac8fd6a125fa1b460b3ca19ece5619 Mon Sep 17 00:00:00 2001 From: Cesar De la Torre Date: Tue, 7 Nov 2017 16:15:03 -0800 Subject: [PATCH] Minor clean-up in Ordering Context --- .../OrderEntityTypeConfiguration.cs | 6 +++--- .../Ordering.Infrastructure/OrderingContext.cs | 11 +---------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs index 19684d5e3..d4eb1fb9a 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs @@ -7,8 +7,7 @@ using System; namespace Ordering.Infrastructure.EntityConfigurations { - class OrderEntityTypeConfiguration - : IEntityTypeConfiguration + class OrderEntityTypeConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder orderConfiguration) { @@ -21,6 +20,7 @@ namespace Ordering.Infrastructure.EntityConfigurations orderConfiguration.Property(o => o.Id) .ForSqlServerUseSequenceHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA); + //Address value object persisted as owned entity type supported since EF Core 2.0 orderConfiguration.OwnsOne(o => o.Address); orderConfiguration.Property("OrderDate").IsRequired(); @@ -32,7 +32,7 @@ namespace Ordering.Infrastructure.EntityConfigurations var navigation = orderConfiguration.Metadata.FindNavigation(nameof(Order.OrderItems)); // DDD Patterns comment: - //Set as Field (New since EF 1.1) to access the OrderItem collection property through its field + //Set as field (New since EF 1.1) to access the OrderItem collection property through its field navigation.SetPropertyAccessMode(PropertyAccessMode.Field); orderConfiguration.HasOne() diff --git a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs index b91f441ba..1855b268a 100644 --- a/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs +++ b/src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs @@ -12,22 +12,14 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure { - public class OrderingContext - : DbContext,IUnitOfWork - + public class OrderingContext : DbContext,IUnitOfWork { public const string DEFAULT_SCHEMA = "ordering"; - public DbSet Orders { get; set; } - public DbSet OrderItems { get; set; } - public DbSet Payments { get; set; } - public DbSet Buyers { get; set; } - public DbSet CardTypes { get; set; } - public DbSet OrderStatus { get; set; } private readonly IMediator _mediator; @@ -63,7 +55,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure // You will need to handle eventual consistency and compensatory actions in case of failures in any of the Handlers. await _mediator.DispatchDomainEventsAsync(this); - // After executing this line all the changes (from the Command Handler and Domain Event Handlers) // performed throught the DbContext will be commited var result = await base.SaveChangesAsync();