Init
This commit is contained in:
64
Prefab.Catalog/Data/Configs/AttributesConfig.cs
Normal file
64
Prefab.Catalog/Data/Configs/AttributesConfig.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user