using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs;
///
/// Configuration class for the entity within the dbo schema.
///
public class GenericAttributeConfig() : EntityConfig(nameof(IPrefabDb.GenericAttributes))
{
///
/// Configuration of Entity Framework mapping for the entity.
///
public override void Configure(EntityTypeBuilder 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();
}
///
/// Validation rules for the entity.
///
public static class Rules
{
///
/// Maximum length to set for the generic attribute key group.
///
public const int KeyGroupMaxLength = 400;
///
/// Minimum length to set for the generic attribute key.
///
public const int KeyMinLength = 3;
///
/// Maximum length to set for the generic attribute key.
///
public const int KeyMaxLength = 400;
///
/// Maximum length to set for the generic attribute value.
///
public const int ValueMaxLength = int.MaxValue;
}
}