Browse Source

Minor clean-up in Ordering Context

pull/417/head
Cesar De la Torre 7 years ago
parent
commit
a88fbf339f
2 changed files with 4 additions and 13 deletions
  1. +3
    -3
      src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs
  2. +1
    -10
      src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs

+ 3
- 3
src/Services/Ordering/Ordering.Infrastructure/EntityConfigurations/OrderEntityTypeConfiguration.cs View File

@ -7,8 +7,7 @@ using System;
namespace Ordering.Infrastructure.EntityConfigurations
{
class OrderEntityTypeConfiguration
: IEntityTypeConfiguration<Order>
class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
{
public void Configure(EntityTypeBuilder<Order> 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<DateTime>("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<PaymentMethod>()


+ 1
- 10
src/Services/Ordering/Ordering.Infrastructure/OrderingContext.cs View File

@ -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<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<PaymentMethod> Payments { get; set; }
public DbSet<Buyer> Buyers { get; set; }
public DbSet<CardType> CardTypes { get; set; }
public DbSet<OrderStatus> 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();


Loading…
Cancel
Save