65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Prefab.Base.Catalog.Attributes;
|
|
using Prefab.Catalog.Domain.Entities;
|
|
|
|
namespace Prefab.Catalog.Data.Configs;
|
|
|
|
public sealed class AttributeDefinitionConfig() : Prefab.Data.Configs.EntityConfig<AttributeDefinition>("AttributeDefinitions", IModuleDb.SchemaName.ToLower())
|
|
{
|
|
public override void Configure(EntityTypeBuilder<AttributeDefinition> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder.HasKey(a => a.Id);
|
|
|
|
builder.Property(a => a.RowVersion)
|
|
.IsRowVersion();
|
|
|
|
builder.Property(a => a.Name)
|
|
.IsRequired()
|
|
.HasMaxLength(AttributeDefinitionRules.NameMaxLength);
|
|
|
|
builder.Property(a => a.Unit)
|
|
.HasMaxLength(AttributeDefinitionRules.UnitMaxLength);
|
|
|
|
builder.HasMany<ProductAttributeValue>()
|
|
.WithOne(v => v.AttributeDefinition)
|
|
.HasForeignKey(v => v.AttributeDefinitionId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|
|
|
|
public sealed class ProductAttributeValueConfig() : Prefab.Data.Configs.EntityConfig<ProductAttributeValue>("ProductAttributeValues", IModuleDb.SchemaName.ToLower())
|
|
{
|
|
public override void Configure(EntityTypeBuilder<ProductAttributeValue> builder)
|
|
{
|
|
base.Configure(builder);
|
|
|
|
builder.HasKey(v => v.Id);
|
|
|
|
builder.Property(v => v.RowVersion)
|
|
.IsRowVersion();
|
|
|
|
builder.Property(v => v.Value)
|
|
.HasMaxLength(ProductAttributeValueRules.ValueMaxLength);
|
|
|
|
builder.Property(v => v.UnitCode)
|
|
.HasMaxLength(ProductAttributeValueRules.UnitCodeMaxLength);
|
|
|
|
builder.Property(v => v.EnumCode)
|
|
.HasMaxLength(ProductAttributeValueRules.EnumCodeMaxLength);
|
|
|
|
builder.Property(v => v.NumericValue)
|
|
.HasPrecision(18, 4);
|
|
|
|
builder.HasIndex(v => new { v.ProductId, v.AttributeDefinitionId })
|
|
.IsUnique();
|
|
|
|
builder.HasOne(v => v.Product)
|
|
.WithMany(p => p.Attributes)
|
|
.HasForeignKey(v => v.ProductId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
}
|