The repetitive fields in the configuration classes in the Ordering.Infrastructure project were gathered here by creating a base class.
This commit is contained in:
parent
4814e1bce2
commit
7abd85796e
@ -0,0 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||
|
||||
namespace Ordering.Infrastructure.EntityConfigurations
|
||||
{
|
||||
public class BaseConfiguration<TEntity> : IEntityTypeConfiguration<TEntity> where TEntity : Entity
|
||||
{
|
||||
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
|
||||
{
|
||||
builder.Ignore(b => b.DomainEvents);
|
||||
builder.HasKey(e => e.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||
|
||||
namespace Ordering.Infrastructure.EntityConfigurations
|
||||
{
|
||||
class BuyerEntityTypeConfiguration
|
||||
: IEntityTypeConfiguration<Buyer>
|
||||
class BuyerEntityTypeConfiguration : BaseConfiguration<Buyer>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Buyer> buyerConfiguration)
|
||||
public override void Configure(EntityTypeBuilder<Buyer> buyerConfiguration)
|
||||
{
|
||||
buyerConfiguration.ToTable("buyers", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
buyerConfiguration.HasKey(b => b.Id);
|
||||
|
||||
buyerConfiguration.Ignore(b => b.DomainEvents);
|
||||
|
||||
buyerConfiguration.Property(b => b.Id)
|
||||
.UseHiLo("buyerseq", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
@ -36,6 +31,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
var navigation = buyerConfiguration.Metadata.FindNavigation(nameof(Buyer.PaymentMethods));
|
||||
|
||||
navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
|
||||
|
||||
base.Configure(buyerConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,12 @@ using System;
|
||||
|
||||
namespace Ordering.Infrastructure.EntityConfigurations
|
||||
{
|
||||
class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
|
||||
class OrderEntityTypeConfiguration : BaseConfiguration<Order>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Order> orderConfiguration)
|
||||
public override void Configure(EntityTypeBuilder<Order> orderConfiguration)
|
||||
{
|
||||
orderConfiguration.ToTable("orders", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
orderConfiguration.HasKey(o => o.Id);
|
||||
|
||||
orderConfiguration.Ignore(b => b.DomainEvents);
|
||||
|
||||
orderConfiguration.Property(o => o.Id)
|
||||
.UseHiLo("orderseq", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
@ -81,6 +77,9 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
.WithMany()
|
||||
// .HasForeignKey("OrderStatusId");
|
||||
.HasForeignKey("_orderStatusId");
|
||||
|
||||
|
||||
base.Configure(orderConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,17 +5,12 @@ using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||
|
||||
namespace Ordering.Infrastructure.EntityConfigurations
|
||||
{
|
||||
class OrderItemEntityTypeConfiguration
|
||||
: IEntityTypeConfiguration<OrderItem>
|
||||
class OrderItemEntityTypeConfiguration : BaseConfiguration<OrderItem>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration)
|
||||
public override void Configure(EntityTypeBuilder<OrderItem> orderItemConfiguration)
|
||||
{
|
||||
orderItemConfiguration.ToTable("orderItems", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
orderItemConfiguration.HasKey(o => o.Id);
|
||||
|
||||
orderItemConfiguration.Ignore(b => b.DomainEvents);
|
||||
|
||||
orderItemConfiguration.Property(o => o.Id)
|
||||
.UseHiLo("orderitemseq");
|
||||
|
||||
@ -54,6 +49,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
.UsePropertyAccessMode(PropertyAccessMode.Field)
|
||||
.HasColumnName("PictureUrl")
|
||||
.IsRequired(false);
|
||||
|
||||
base.Configure(orderItemConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,17 +6,12 @@ using System;
|
||||
|
||||
namespace Ordering.Infrastructure.EntityConfigurations
|
||||
{
|
||||
class PaymentMethodEntityTypeConfiguration
|
||||
: IEntityTypeConfiguration<PaymentMethod>
|
||||
class PaymentMethodEntityTypeConfiguration : BaseConfiguration<PaymentMethod>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
|
||||
public override void Configure(EntityTypeBuilder<PaymentMethod> paymentConfiguration)
|
||||
{
|
||||
paymentConfiguration.ToTable("paymentmethods", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
paymentConfiguration.HasKey(b => b.Id);
|
||||
|
||||
paymentConfiguration.Ignore(b => b.DomainEvents);
|
||||
|
||||
paymentConfiguration.Property(b => b.Id)
|
||||
.UseHiLo("paymentseq", OrderingContext.DEFAULT_SCHEMA);
|
||||
|
||||
@ -60,6 +55,8 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
||||
paymentConfiguration.HasOne(p => p.CardType)
|
||||
.WithMany()
|
||||
.HasForeignKey("_cardTypeId");
|
||||
|
||||
base.Configure(paymentConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user