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

28 lines
898 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Prefab.Data.Configs
{
/// <summary>
/// Base configuration for all entities, sets items like table name and schema.
/// </summary>
/// <typeparam name="T">The entity type.</typeparam>
public abstract class EntityConfig<T> : IEntityTypeConfiguration<T> where T : class
{
private readonly string _schema;
private readonly string _tableName;
protected EntityConfig(string tableName, string? schema = null)
{
ArgumentException.ThrowIfNullOrWhiteSpace(tableName);
_tableName = tableName;
_schema = string.IsNullOrWhiteSpace(schema) ? "dbo" : schema;
}
public virtual void Configure(EntityTypeBuilder<T> builder)
{
builder.ToTable(_tableName, _schema);
}
}
}