28 lines
898 B
C#
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);
|
|
}
|
|
}
|
|
}
|