49 lines
1.6 KiB
C#
49 lines
1.6 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="AuditLog"/> entity.
|
|
/// </summary>
|
|
public class AuditLogConfig() : Prefab.Data.Configs.EntityConfig<AuditLog>(nameof(IPrefabDb.AuditLogs))
|
|
{
|
|
/// <summary>
|
|
/// Configures the properties and relationships for the <see cref="AuditLog"/> entity.
|
|
/// </summary>
|
|
/// <param name="builder">The builder to be used to configure the entity type.</param>
|
|
public override void Configure(EntityTypeBuilder<AuditLog> builder)
|
|
{
|
|
builder.HasKey(e => e.Id);
|
|
|
|
builder.Property(e => e.Entity)
|
|
.HasMaxLength(Rules.EntityMaxLength)
|
|
.IsRequired();
|
|
|
|
builder.Property(e => e.State)
|
|
.IsRequired();
|
|
|
|
builder.Property(e => e.CreatedBy)
|
|
.IsRequired();
|
|
|
|
builder.Property(e => e.CreatedOn)
|
|
.IsRequired();
|
|
|
|
builder.HasMany(e => e.Items)
|
|
.WithOne(i => i.AuditLog)
|
|
.HasForeignKey(i => i.AuditLogId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validation rules and settings for <see cref="AuditLog"/> properties.
|
|
/// </summary>
|
|
public static class Rules
|
|
{
|
|
/// <summary>Maximum length for the Entity name.</summary>
|
|
public const int EntityMaxLength = 200;
|
|
}
|
|
}
|
|
}
|