ERPDbContext.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. /// Customers table
  30. /// </summary>
  31. public DbSet<Customer> Customers { get; set; }
  32. /// <summary>
  33. /// Employees table
  34. /// </summary>
  35. public DbSet<Employee> Employees { get; set; }
  36. /// <summary>
  37. /// Employee degrees table
  38. /// </summary>
  39. public DbSet<EmployeeDegree> EmployeeDegrees { get; set; }
  40. /// <summary>
  41. /// Materials table
  42. /// </summary>
  43. public DbSet<Material> Materials { get; set; }
  44. /// <summary>
  45. /// Suppliers table
  46. /// </summary>
  47. public DbSet<Supplier> Suppliers { get; set; }
  48. /// <summary>
  49. /// Taxes table
  50. /// </summary>
  51. public DbSet<Tax> Taxes { get; set; }
  52. /// <summary>
  53. /// Units table
  54. /// </summary>
  55. public DbSet<Unit> Units { get; set; }
  56. /// <summary>
  57. /// Users table
  58. /// </summary>
  59. public DbSet<User> Users { get; set; }
  60. /// <summary>
  61. /// Policies table
  62. /// </summary>
  63. public DbSet<Policy> Policies { get; set; }
  64. /// <summary>
  65. /// UserPolicies table
  66. /// </summary>
  67. public DbSet<UserPolicy> UserPolicies { get; set; }
  68. #endregion
  69. #region Constructor
  70. /// <summary>
  71. /// Initializes a new instance of the ERPDbContext class
  72. /// </summary>
  73. /// <param name="options">Database context options.</param>
  74. public ERPDbContext(DbContextOptions options) : base(options)
  75. {
  76. }
  77. #endregion
  78. #region Overrides
  79. /// <summary>
  80. /// Model creation override method to initialize the necessary model mappings
  81. /// </summary>
  82. /// <param name="modelBuilder">The model builder.</param>
  83. protected override void OnModelCreating(ModelBuilder modelBuilder)
  84. {
  85. modelBuilder.ApplyConfiguration(new CraftEmployeeMapping());
  86. modelBuilder.ApplyConfiguration(new CraftMapping());
  87. modelBuilder.ApplyConfiguration(new CraftMaterialMapping());
  88. modelBuilder.ApplyConfiguration(new CustomerMapping());
  89. modelBuilder.ApplyConfiguration(new EmployeeDegreeMapping());
  90. modelBuilder.ApplyConfiguration(new EmployeeMapping());
  91. modelBuilder.ApplyConfiguration(new MaterialMapping());
  92. modelBuilder.ApplyConfiguration(new SupplierMapping());
  93. modelBuilder.ApplyConfiguration(new TaxMapping());
  94. modelBuilder.ApplyConfiguration(new UnitMapping());
  95. modelBuilder.ApplyConfiguration(new UserMapping());
  96. modelBuilder.ApplyConfiguration(new PolicyMapping());
  97. modelBuilder.ApplyConfiguration(new UserPolicyMapping());
  98. }
  99. #endregion
  100. #region Data
  101. /// <summary>
  102. /// Create seed data for the model database
  103. /// </summary>
  104. /// <typeparam name="T">The entity type gaining the seed data.</typeparam>
  105. /// <param name="modelBuilder">The basted model builder.</param>
  106. /// <param name="data">The seeded data.</param>
  107. private void CreateSeedDate<T>(ModelBuilder modelBuilder, params T[] data)
  108. {
  109. modelBuilder.Entity(typeof(T))
  110. .HasData(data);
  111. }
  112. #endregion
  113. }
  114. }