mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 22:26:34 +00:00
34 lines
1.0 KiB
C#
34 lines
1.0 KiB
C#
using Azaion.Common.Entities;
|
|
using LinqToDB;
|
|
using LinqToDB.Mapping;
|
|
|
|
namespace Azaion.Common.Database;
|
|
|
|
public static class AzaionDbSchemaHolder
|
|
{
|
|
public static readonly MappingSchema MappingSchema;
|
|
|
|
static AzaionDbSchemaHolder()
|
|
{
|
|
MappingSchema = new MappingSchema();
|
|
|
|
MappingSchema.EntityDescriptorCreatedCallback = (_, entityDescriptor) =>
|
|
{
|
|
foreach (var entityDescriptorColumn in entityDescriptor.Columns)
|
|
entityDescriptorColumn.ColumnName = entityDescriptorColumn.ColumnName.ToSnakeCase();
|
|
};
|
|
|
|
var builder = new FluentMappingBuilder(MappingSchema);
|
|
|
|
builder.Entity<User>()
|
|
.HasTableName("users")
|
|
.Property(x => x.Id)
|
|
.IsPrimaryKey()
|
|
.HasDataType(DataType.Guid)
|
|
.Property(x => x.Role)
|
|
.HasDataType(DataType.Text)
|
|
.HasConversion(v => v.ToString(), v => (RoleEnum)Enum.Parse(typeof(RoleEnum), v));
|
|
|
|
builder.Build();
|
|
}
|
|
} |