using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using GreenTree.Strohrmann.ERP.Core.Domain.Rights; using GreenTree.Strohrmann.ERP.Domain.Model.Rights; using System; using System.Collections.Generic; using System.Reflection; using System.Text; using GreenTree.Strohrmann.ERP.Core.Domain.Business; using GreenTree.Strohrmann.ERP.Domain.Model.Business; namespace GreenTree.Strohrmann.ERP.Domain.Model { public class ERPDbContext : DbContext { #region Tables /// /// Crafts table /// public DbSet Crafts { get; set; } /// /// Craft employees trable /// public DbSet CraftEmployees { get; set; } /// /// Craft materials table /// public DbSet CraftMaterials { get; set; } /// /// Customers table /// public DbSet Customers { get; set; } /// /// Employees table /// public DbSet Employees { get; set; } /// /// Employee degrees table /// public DbSet EmployeeDegrees { get; set; } /// /// Materials table /// public DbSet Materials { get; set; } /// /// Suppliers table /// public DbSet Suppliers { get; set; } /// /// Taxes table /// public DbSet Taxes { get; set; } /// /// Units table /// public DbSet Units { get; set; } /// /// Users table /// public DbSet Users { get; set; } /// /// Policies table /// public DbSet Policies { get; set; } /// /// UserPolicies table /// public DbSet UserPolicies { get; set; } #endregion #region Constructor /// /// Initializes a new instance of the ERPDbContext class /// /// Database context options. public ERPDbContext(DbContextOptions options) : base(options) { } #endregion #region Overrides /// /// Model creation override method to initialize the necessary model mappings /// /// The model builder. protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfiguration(new CraftEmployeeMapping()); modelBuilder.ApplyConfiguration(new CraftMapping()); modelBuilder.ApplyConfiguration(new CraftMaterialMapping()); modelBuilder.ApplyConfiguration(new CustomerMapping()); modelBuilder.ApplyConfiguration(new EmployeeDegreeMapping()); modelBuilder.ApplyConfiguration(new EmployeeMapping()); modelBuilder.ApplyConfiguration(new MaterialMapping()); modelBuilder.ApplyConfiguration(new SupplierMapping()); modelBuilder.ApplyConfiguration(new TaxMapping()); modelBuilder.ApplyConfiguration(new UnitMapping()); modelBuilder.ApplyConfiguration(new UserMapping()); modelBuilder.ApplyConfiguration(new PolicyMapping()); modelBuilder.ApplyConfiguration(new UserPolicyMapping()); } #endregion #region Data /// /// Create seed data for the model database /// /// The entity type gaining the seed data. /// The basted model builder. /// The seeded data. private void CreateSeedDate(ModelBuilder modelBuilder, params T[] data) { modelBuilder.Entity(typeof(T)) .HasData(data); } #endregion } }