Files
prefab-page-detail/Prefab/Data/Configs/GenericAttributeConfig.cs
2025-10-27 17:39:18 -04:00

72 lines
2.3 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs;
/// <summary>
/// Configuration class for the <see cref="GenericAttribute"/> entity within the dbo schema.
/// </summary>
public class GenericAttributeConfig() : EntityConfig<GenericAttribute>(nameof(IPrefabDb.GenericAttributes))
{
/// <summary>
/// Configuration of Entity Framework mapping for the <see cref="GenericAttribute"/> entity.
/// </summary>
public override void Configure(EntityTypeBuilder<GenericAttribute> builder)
{
builder
.Ignore(x => x.Id);
// Define the composite key (and clustered index) for the GenericAttribute entity.
builder
.HasKey(x => new { x.EntityId, x.KeyGroup, x.Key });
builder.HasIndex(x => new { x.EntityId, x.KeyGroup })
.HasDatabaseName("IX_GenericAttributes_Entity_Group");
builder.HasIndex(x => x.DeletedOn)
.HasFilter("[DeletedOn] IS NULL")
.HasDatabaseName("IX_GenericAttributes_Active");
builder
.Property(x => x.KeyGroup)
.HasMaxLength(Rules.KeyGroupMaxLength)
.IsRequired();
builder
.Property(x => x.Key)
.HasMaxLength(Rules.KeyMaxLength)
.IsRequired();
builder
.Property(x => x.Value)
.HasMaxLength(Rules.ValueMaxLength)
.IsRequired();
}
/// <summary>
/// Validation rules for the <see cref="GenericAttribute"/> entity.
/// </summary>
public static class Rules
{
/// <summary>
/// Maximum length to set for the generic attribute key group.
/// </summary>
public const int KeyGroupMaxLength = 400;
/// <summary>
/// Minimum length to set for the generic attribute key.
/// </summary>
public const int KeyMinLength = 3;
/// <summary>
/// Maximum length to set for the generic attribute key.
/// </summary>
public const int KeyMaxLength = 400;
/// <summary>
/// Maximum length to set for the generic attribute value.
/// </summary>
public const int ValueMaxLength = int.MaxValue;
}
}