// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Persistence.EntityFramework; using Microsoft.EntityFrameworkCore; using MUnique.OpenMU.Persistence.EntityFramework.Extensions; using MUnique.OpenMU.Persistence.EntityFramework.Model; /// /// Context for the guild server which just uses , and . /// public class GuildContext : DbContext { /// /// Configures the model, especially defines that and are created in a separate "guild" schema. /// /// The model builder. internal static void ConfigureModel(ModelBuilder modelBuilder) { modelBuilder.Entity(member => { member.Property(m => m.Id).ValueGeneratedNever(); member.ToTable(nameof(GuildMember), SchemaNames.Guild); }); modelBuilder.Entity(e => { e.Property(guild => guild.Name).HasMaxLength(8).IsRequired(); e.HasIndex(guild => guild.Name).IsUnique(); e.ToTable(nameof(Guild), SchemaNames.Guild); }); } /// protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); this.Configure(optionsBuilder); } /// protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Ignore(); ConfigureModel(modelBuilder); modelBuilder.Entity().Ignore(m => m.Character); modelBuilder.Entity().HasKey(f => f.Id); modelBuilder.UseGuidV7Ids(); } }