ERPDbContext.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.Extensions.Configuration;
  3. using GreenTree.Strohrmann.ERP.Core.Domain.Rights;
  4. using GreenTree.Strohrmann.ERP.Domain.Model.Rights;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Reflection;
  8. using System.Text;
  9. using GreenTree.Strohrmann.ERP.Core.Domain.Business;
  10. using GreenTree.Strohrmann.ERP.Domain.Model.Business;
  11. namespace GreenTree.Strohrmann.ERP.Domain.Model
  12. {
  13. public class ERPDbContext : DbContext
  14. {
  15. #region Tables
  16. /// <summary>
  17. /// Crafts table
  18. /// </summary>
  19. public DbSet<Craft> Crafts { get; set; }
  20. /// <summary>
  21. /// Craft employees trable
  22. /// </summary>
  23. public DbSet<CraftEmployee> CraftEmployees { get; set; }
  24. /// <summary>
  25. /// Craft materials table
  26. /// </summary>
  27. public DbSet<CraftMaterial> CraftMaterials { get; set; }
  28. /// <summary>
  29. /// Customer titles table
  30. /// </summary>
  31. public DbSet<Title> Titles { get; set; }
  32. /// <summary>
  33. /// Customers table
  34. /// </summary>
  35. public DbSet<Customer> Customers { get; set; }
  36. /// <summary>
  37. /// Employees table
  38. /// </summary>
  39. public DbSet<Employee> Employees { get; set; }
  40. /// <summary>
  41. /// Employee degrees table
  42. /// </summary>
  43. public DbSet<EmployeeDegree> EmployeeDegrees { get; set; }
  44. /// <summary>
  45. /// Materials table
  46. /// </summary>
  47. public DbSet<Material> Materials { get; set; }
  48. /// <summary>
  49. /// Suppliers table
  50. /// </summary>
  51. public DbSet<Supplier> Suppliers { get; set; }
  52. /// <summary>
  53. /// Taxes table
  54. /// </summary>
  55. public DbSet<Tax> Taxes { get; set; }
  56. /// <summary>
  57. /// Units table
  58. /// </summary>
  59. public DbSet<Unit> Units { get; set; }
  60. /// <summary>
  61. /// Users table
  62. /// </summary>
  63. public DbSet<User> Users { get; set; }
  64. /// <summary>
  65. /// Policies table
  66. /// </summary>
  67. public DbSet<Policy> Policies { get; set; }
  68. /// <summary>
  69. /// UserPolicies table
  70. /// </summary>
  71. public DbSet<UserPolicy> UserPolicies { get; set; }
  72. #endregion
  73. #region Constructor
  74. /// <summary>
  75. /// Initializes a new instance of the ERPDbContext class
  76. /// </summary>
  77. /// <param name="options">Database context options.</param>
  78. public ERPDbContext(DbContextOptions options) : base(options)
  79. {
  80. }
  81. #endregion
  82. #region Overrides
  83. /// <summary>
  84. /// Model creation override method to initialize the necessary model mappings
  85. /// </summary>
  86. /// <param name="modelBuilder">The model builder.</param>
  87. protected override void OnModelCreating(ModelBuilder modelBuilder)
  88. {
  89. modelBuilder.ApplyConfiguration(new CraftEmployeeMapping());
  90. modelBuilder.ApplyConfiguration(new CraftMapping());
  91. modelBuilder.ApplyConfiguration(new CraftMaterialMapping());
  92. modelBuilder.ApplyConfiguration(new TitleMapping());
  93. modelBuilder.ApplyConfiguration(new CustomerMapping());
  94. modelBuilder.ApplyConfiguration(new EmployeeDegreeMapping());
  95. modelBuilder.ApplyConfiguration(new EmployeeMapping());
  96. modelBuilder.ApplyConfiguration(new MaterialMapping());
  97. modelBuilder.ApplyConfiguration(new SupplierMapping());
  98. modelBuilder.ApplyConfiguration(new TaxMapping());
  99. modelBuilder.ApplyConfiguration(new UnitMapping());
  100. modelBuilder.ApplyConfiguration(new UserMapping());
  101. modelBuilder.ApplyConfiguration(new PolicyMapping());
  102. modelBuilder.ApplyConfiguration(new UserPolicyMapping());
  103. }
  104. #endregion
  105. #region Data
  106. /// <summary>
  107. /// Create seed data for the model database
  108. /// </summary>
  109. /// <typeparam name="T">The entity type gaining the seed data.</typeparam>
  110. /// <param name="modelBuilder">The basted model builder.</param>
  111. /// <param name="data">The seeded data.</param>
  112. private void CreateSeedDate<T>(ModelBuilder modelBuilder, params T[] data)
  113. {
  114. modelBuilder.Entity(typeof(T))
  115. .HasData(data);
  116. }
  117. #endregion
  118. }
  119. }