Init
This commit is contained in:
27
Prefab/Data/Configs/EntityConfig.cs
Normal file
27
Prefab/Data/Configs/EntityConfig.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user