- Made parents nullable - Added a data key for the tree - Added depth for quicker layer-wise loading
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.EntityFrameworkCore;
 | |
| 
 | |
| namespace DataModel.Database.Common;
 | |
| 
 | |
| public sealed class DataContext : DbContext
 | |
| {
 | |
|     public DbSet<Setting>? Settings { get; set; }
 | |
| 
 | |
|     public DbSet<Section>? Sections { get; set; }
 | |
| 
 | |
|     public DbSet<TextElement>? TextElements { get; set; }
 | |
| 
 | |
|     public DbSet<Translation>? Translations { get; set; }
 | |
| 
 | |
|     public DataContext(DbContextOptions<DataContext> contextOptions) : base(contextOptions)
 | |
|     {
 | |
|     }
 | |
|     
 | |
|     protected override void OnModelCreating(ModelBuilder modelBuilder)
 | |
|     {
 | |
|         base.OnModelCreating(modelBuilder);
 | |
| 
 | |
|         #region Settings
 | |
|         
 | |
|         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
 | |
| 
 | |
|         #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);
 | |
| 
 | |
|         #endregion
 | |
| 
 | |
|         #region TextElements
 | |
| 
 | |
|         modelBuilder.Entity<TextElement>().HasIndex(n => n.Id);
 | |
|         modelBuilder.Entity<TextElement>().HasIndex(n => n.Code);
 | |
| 
 | |
|         #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
 | |
|     }
 | |
| } |