OrderDbContext.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. namespace GreenTree.Maschinenbestellungen.Domain.Model
  10. {
  11. public class OrderDbContext : 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 OrderDbContext(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. #region Data
  49. /// <summary>
  50. /// Create seed data for the model database
  51. /// </summary>
  52. /// <typeparam name="T">The entity type gaining the seed data.</typeparam>
  53. /// <param name="modelBuilder">The basted model builder.</param>
  54. /// <param name="data">The seeded data.</param>
  55. private void CreateSeedDate<T>(ModelBuilder modelBuilder, params T[] data)
  56. {
  57. modelBuilder.Entity(typeof(T))
  58. .HasData(data);
  59. }
  60. #endregion
  61. }
  62. }