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);
|
2022-07-25 17:03:49 +00:00
|
|
|
|
modelBuilder.Entity<Setting>().HasIndex(n => n.Code).IsUnique();
|
2022-06-12 15:15:30 +00:00
|
|
|
|
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);
|
2022-07-09 13:03:18 +00:00
|
|
|
|
modelBuilder.Entity<Section>().HasIndex(n => n.Depth);
|
|
|
|
|
modelBuilder.Entity<Section>().HasIndex(n => n.DataKey);
|
2022-07-16 20:28:40 +00:00
|
|
|
|
// modelBuilder.Entity<Section>().Navigation(n => n.Parent).AutoInclude(); // Cycle-reference, does not work, though.
|
2022-07-13 18:04:26 +00:00
|
|
|
|
modelBuilder.Entity<Section>().Navigation(n => n.TextElements).AutoInclude();
|
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-07-13 18:04:26 +00:00
|
|
|
|
modelBuilder.Entity<TextElement>().Navigation(n => n.Section).AutoInclude();
|
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);
|
2022-07-13 18:04:26 +00:00
|
|
|
|
modelBuilder.Entity<Translation>().Navigation(n => n.TextElement).AutoInclude();
|
2022-06-12 19:42:47 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
2022-06-12 15:15:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|