using System; using System.Collections.Generic; using Datamodels.Lookups; using Datamodels.DatabaseModels; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; namespace Repositories { public class FwDbContext: DbContext { public string _connectionString { get; set; } = "SERVER=127.0.0.1;DATABASE=testdb;PORT=3306;USER=root;PASSWORD=example"; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var version = new MariaDbServerVersion(new Version(10,5)); optionsBuilder.UseMySql(_connectionString, version); } public DbSet LookupCategories { get; set; } public DbSet LookupValues { get; set; } public DbSet
Address { get; set; } public DbSet Person { get; set; } public DbSet Communication { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasKey(x => x.Id); modelBuilder.Entity() .Property(x => x.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() .HasKey(x => x.Id); modelBuilder.Entity() .Property(x => x.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() .HasMany(x => x.LookupValues) .WithOne(y => y.LookupCategory); modelBuilder.Entity() .Property(x => x.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() .HasKey(x => x.Id); modelBuilder.Entity() .HasMany(x => x.Communications) .WithOne(y => y.Person); modelBuilder.Entity() .HasMany(x => x.Addresses) .WithOne(y => y.Person); modelBuilder.Entity
() .Property(x => x.Id).ValueGeneratedOnAdd(); modelBuilder.Entity
() .HasKey(x => x.Id); modelBuilder.Entity() .Property(x => x.Id).ValueGeneratedOnAdd(); modelBuilder.Entity() .HasKey(x => x.Id); } } }