ERPDbContext.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace GreenTree.Strohrmann.ERP.Domain.Model
  10. {
  11. public class ERPDbContext : DbContext
  12. {
  13. #region Tables
  14. /// <summary>
  15. /// Users table
  16. /// </summary>
  17. public DbSet<User> Users { get; set; }
  18. /// <summary>
  19. /// Policies table
  20. /// </summary>
  21. public DbSet<Policy> Policies { get; set; }
  22. /// <summary>
  23. /// UserPolicies table
  24. /// </summary>
  25. public DbSet<UserPolicy> UserPolicies { get; set; }
  26. #endregion
  27. #region Constructor
  28. /// <summary>
  29. /// Initializes a new instance of the ERPDbContext class
  30. /// </summary>
  31. /// <param name="options">Database context options.</param>
  32. public ERPDbContext(DbContextOptions options) : base(options)
  33. {
  34. }
  35. #endregion
  36. #region Overrides
  37. /// <summary>
  38. /// Model creation override method to initialize the necessary model mappings
  39. /// </summary>
  40. /// <param name="modelBuilder">The model builder.</param>
  41. protected override void OnModelCreating(ModelBuilder modelBuilder)
  42. {
  43. modelBuilder.ApplyConfiguration(new UserMapping());
  44. modelBuilder.ApplyConfiguration(new PolicyMapping());
  45. modelBuilder.ApplyConfiguration(new UserPolicyMapping());
  46. }
  47. #endregion
  48. }
  49. }