Added main entities

This commit is contained in:
tsommer committed 2022-06-12 21:42:47 +02:00
1 parent c93c903c26
commit 50ffcb33b1
5 files changed
+72 -2

No files matched your search

@@ -6,6 +6,12 @@ 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)
{
}
@@ -14,7 +20,7 @@ public sealed class DataContext : DbContext
{
base.OnModelCreating(modelBuilder);
#region Ideas
#region Settings
modelBuilder.Entity<Setting>().HasIndex(n => n.Id);
modelBuilder.Entity<Setting>().HasIndex(n => n.Name).IsUnique();
@@ -24,5 +30,27 @@ public sealed class DataContext : DbContext
modelBuilder.Entity<Setting>().HasIndex(n => n.TextValue);
#endregion
#region Sections
modelBuilder.Entity<Section>().HasIndex(n => n.Id);
modelBuilder.Entity<Section>().HasIndex(n => n.Name);
#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
}
}
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace DataModel.Database;
public sealed class Section
{
[Key]
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public Section Parent { get; set; }
public List<TextElement> TextElements { get; set; }
}
+1 -1
View File
@@ -2,7 +2,7 @@
namespace DataModel.Database;
public class Setting
public sealed class Setting
{
[Key]
public int Id { get; set; }
@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace DataModel.Database;
public sealed class TextElement
{
[Key]
public int Id { get; set; }
public string Code { get; set; } = string.Empty;
public Section Section { get; set; }
public List<Translation> Translations { get; set; }
}
@@ -0,0 +1,12 @@
namespace DataModel.Database;
public sealed class Translation
{
public int Id { get; set; }
public TextElement TextElement { get; set; }
public string Culture { get; set; } = "en-US";
public string Text { get; set; } = string.Empty;
}