OrderDbContext.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Microsoft.EntityFrameworkCore;
  2. using Microsoft.Extensions.Configuration;
  3. using GreenTree.Maschinenbestellungen.Core.Domain.Rights;
  4. using GreenTree.Maschinenbestellungen.Domain.Model.Rights;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Reflection;
  8. using System.Text;
  9. using GreenTree.Maschinenbestellungen.Core.Domain.Business;
  10. using GreenTree.Maschinenbestellungen.Domain.Model.Business;
  11. namespace GreenTree.Maschinenbestellungen.Domain.Model
  12. {
  13. public class OrderDbContext : DbContext
  14. {
  15. #region Tables
  16. /// <summary>
  17. /// Users table
  18. /// </summary>
  19. public DbSet<User> Users { get; set; }
  20. /// <summary>
  21. /// Policies table
  22. /// </summary>
  23. public DbSet<Policy> Policies { get; set; }
  24. /// <summary>
  25. /// UserPolicies table
  26. /// </summary>
  27. public DbSet<UserPolicy> UserPolicies { get; set; }
  28. #endregion
  29. #region Constructor
  30. /// <summary>
  31. /// Initializes a new instance of the ERPDbContext class
  32. /// </summary>
  33. /// <param name="options">Database context options.</param>
  34. public OrderDbContext(DbContextOptions options) : base(options)
  35. {
  36. }
  37. #endregion
  38. #region Overrides
  39. /// <summary>
  40. /// Model creation override method to initialize the necessary model mappings
  41. /// </summary>
  42. /// <param name="modelBuilder">The model builder.</param>
  43. protected override void OnModelCreating(ModelBuilder modelBuilder)
  44. {
  45. modelBuilder.ApplyConfiguration(new UserMapping());
  46. modelBuilder.ApplyConfiguration(new PolicyMapping());
  47. modelBuilder.ApplyConfiguration(new UserPolicyMapping());
  48. }
  49. #endregion
  50. #region Data
  51. /// <summary>
  52. /// Create seed data for the model database
  53. /// </summary>
  54. /// <typeparam name="T">The entity type gaining the seed data.</typeparam>
  55. /// <param name="modelBuilder">The basted model builder.</param>
  56. /// <param name="data">The seeded data.</param>
  57. private void CreateSeedDate<T>(ModelBuilder modelBuilder, params T[] data)
  58. {
  59. modelBuilder.Entity(typeof(T))
  60. .HasData(data);
  61. }
  62. #endregion
  63. }
  64. }