ERPDbContext.cs 4.0 KB

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