49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Prefab.Data.Entities;
|
|
|
|
namespace Prefab.Data.Configs
|
|
{
|
|
/// <summary>
|
|
/// Entity Framework Core configuration for the <see cref="AuditLogItem"/> entity.
|
|
/// </summary>
|
|
public class AuditLogItemConfig() : Prefab.Data.Configs.EntityConfig<AuditLogItem>(nameof(IPrefabDb.AuditLogItems))
|
|
{
|
|
/// <summary>
|
|
/// Configures the properties and relationships for the <see cref="AuditLogItem"/> entity.
|
|
/// </summary>
|
|
/// <param name="builder">The builder to be used to configure the entity type.</param>
|
|
public override void Configure(EntityTypeBuilder<AuditLogItem> builder)
|
|
{
|
|
builder.HasKey(e => e.Id);
|
|
|
|
builder.Property(e => e.Property)
|
|
.HasMaxLength(Rules.PropertyMaxLength)
|
|
.IsRequired();
|
|
|
|
builder.Property(e => e.OldValue)
|
|
.HasMaxLength(Rules.ValueMaxLength);
|
|
|
|
builder.Property(e => e.NewValue)
|
|
.HasMaxLength(Rules.ValueMaxLength);
|
|
|
|
builder.HasOne(e => e.AuditLog)
|
|
.WithMany(a => a.Items)
|
|
.HasForeignKey(e => e.AuditLogId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validation rules and settings for <see cref="AuditLogItem"/> properties.
|
|
/// </summary>
|
|
public static class Rules
|
|
{
|
|
/// <summary>Maximum length for the property name.</summary>
|
|
public const int PropertyMaxLength = 100;
|
|
/// <summary>Maximum length for the value fields.</summary>
|
|
public const int ValueMaxLength = 1000;
|
|
}
|
|
}
|
|
}
|
|
|