I18NCommander/I18N Commander/DataModel/Database/Common/DataContext.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2022-06-12 15:15:30 +00:00
using Microsoft.EntityFrameworkCore;
namespace DataModel.Database.Common;
public sealed class DataContext : DbContext
{
2022-07-09 13:03:50 +00:00
public DbSet<Setting> Settings { get; set; }
2022-06-12 15:15:30 +00:00
2022-07-09 13:03:50 +00:00
public DbSet<Section> Sections { get; set; }
2022-06-12 19:42:47 +00:00
2022-07-09 13:03:50 +00:00
public DbSet<TextElement> TextElements { get; set; }
2022-06-12 19:42:47 +00:00
2022-07-09 13:03:50 +00:00
public DbSet<Translation> Translations { get; set; }
2022-06-12 19:42:47 +00:00
2022-06-12 15:15:30 +00:00
public DataContext(DbContextOptions<DataContext> contextOptions) : base(contextOptions)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
2022-06-12 19:42:47 +00:00
#region Settings
2022-06-12 15:15:30 +00:00
modelBuilder.Entity<Setting>().HasIndex(n => n.Id);
modelBuilder.Entity<Setting>().HasIndex(n => n.Name).IsUnique();
modelBuilder.Entity<Setting>().HasIndex(n => n.BoolValue);
modelBuilder.Entity<Setting>().HasIndex(n => n.GuidValue);
modelBuilder.Entity<Setting>().HasIndex(n => n.IntegerValue);
modelBuilder.Entity<Setting>().HasIndex(n => n.TextValue);
#endregion
2022-06-12 19:42:47 +00:00
#region Sections
modelBuilder.Entity<Section>().HasIndex(n => n.Id);
modelBuilder.Entity<Section>().HasIndex(n => n.Name);
modelBuilder.Entity<Section>().HasIndex(n => n.Depth);
modelBuilder.Entity<Section>().HasIndex(n => n.DataKey);
2022-06-12 19:42:47 +00:00
#endregion
#region TextElements
modelBuilder.Entity<TextElement>().HasIndex(n => n.Id);
modelBuilder.Entity<TextElement>().HasIndex(n => n.Code);
2022-07-10 17:30:22 +00:00
modelBuilder.Entity<TextElement>().HasIndex(n => n.Name);
2022-06-12 19:42:47 +00:00
#endregion
#region Translations
modelBuilder.Entity<Translation>().HasIndex(n => n.Id);
modelBuilder.Entity<Translation>().HasIndex(n => n.Culture);
modelBuilder.Entity<Translation>().HasIndex(n => n.Text);
#endregion
2022-06-12 15:15:30 +00:00
}
}