using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Prefab.Data.Entities;
namespace Prefab.Data.Configs
{
///
/// Entity Framework Core configuration for the entity.
///
public class AuditLogConfig() : Prefab.Data.Configs.EntityConfig(nameof(IPrefabDb.AuditLogs))
{
///
/// Configures the properties and relationships for the entity.
///
/// The builder to be used to configure the entity type.
public override void Configure(EntityTypeBuilder 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);
}
///
/// Validation rules and settings for properties.
///
public static class Rules
{
/// Maximum length for the Entity name.
public const int EntityMaxLength = 200;
}
}
}