using Microsoft.EntityFrameworkCore; namespace DataModel.Database.Common; public sealed class DataContext : DbContext, IDataContext { public DbSet Settings { get; set; } public DbSet
Sections { get; set; } public DbSet TextElements { get; set; } public DbSet Translations { get; set; } public DataContext(DbContextOptions contextOptions) : base(contextOptions) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); #region Settings modelBuilder.Entity().HasIndex(n => n.Id); modelBuilder.Entity().HasIndex(n => n.Code).IsUnique(); modelBuilder.Entity().HasIndex(n => n.BoolValue); modelBuilder.Entity().HasIndex(n => n.GuidValue); modelBuilder.Entity().HasIndex(n => n.IntegerValue); modelBuilder.Entity().HasIndex(n => n.TextValue); #endregion #region Sections modelBuilder.Entity
().HasIndex(n => n.Id); modelBuilder.Entity
().HasIndex(n => n.Name); modelBuilder.Entity
().HasIndex(n => n.Depth); modelBuilder.Entity
().HasIndex(n => n.DataKey); // modelBuilder.Entity
().Navigation(n => n.Parent).AutoInclude(); // Cycle-reference, does not work, though. modelBuilder.Entity
().Navigation(n => n.TextElements).AutoInclude(); #endregion #region TextElements modelBuilder.Entity().HasIndex(n => n.Id); modelBuilder.Entity().HasIndex(n => n.Code); modelBuilder.Entity().HasIndex(n => n.Name); modelBuilder.Entity().HasIndex(n => n.IsMultiLine); modelBuilder.Entity().Navigation(n => n.Section).AutoInclude(); #endregion #region Translations modelBuilder.Entity().HasIndex(n => n.Id); modelBuilder.Entity().HasIndex(n => n.Culture); modelBuilder.Entity().HasIndex(n => n.Text); modelBuilder.Entity().Navigation(n => n.TextElement).AutoInclude(); #endregion } }