LookingGlass/Data/LookingGlassContext.cs

26 lines
868 B
C#
Raw Normal View History

2025-01-29 18:09:21 +00:00
using Microsoft.EntityFrameworkCore;
2025-01-29 21:04:56 +00:00
using static EnumStringValues.EnumExtensions;
2025-01-29 18:09:21 +00:00
namespace LookingGlass.Data
2025-01-29 18:09:21 +00:00
{
public class ApplicationContext(DbContextOptions<ApplicationContext> options)
: DbContext(options)
2025-01-29 18:09:21 +00:00
{
2025-01-29 21:04:56 +00:00
public DbSet<Moderation> Moderation { get; set; } = default!;
2025-01-30 17:48:16 +00:00
public DbSet<User> User { get; set; } = default!;
2025-01-29 18:09:21 +00:00
2025-01-29 21:04:56 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Moderation>()
.Property(m => m.Type)
.HasConversion(v => v.GetStringValue(), v => v.ParseToEnum<ModerationTypes>());
modelBuilder
.Entity<Moderation>()
.Property(m => m.ReasonType)
.HasConversion(v => v.GetStringValue(), v => v.ParseToEnum<ModerationReasons>());
}
2025-01-29 18:09:21 +00:00
}
}