IwbDbContext.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using IwbZero.EntityFramework;
  2. using System.Data.Common;
  3. using System.Data.Entity;
  4. using System.Data.Entity.ModelConfiguration.Conventions;
  5. using WeApp.Authorization.Roles;
  6. using WeApp.Authorization.Users;
  7. using WeApp.BaseInfo;
  8. using WeApp.BasicInfo;
  9. using WeApp.MultiTenancy;
  10. using WeApp.TrainingCamp;
  11. namespace WeApp.EF
  12. {
  13. public class WeAppDbContext : IwbZeroDbContext<Tenant, Role, User>
  14. {
  15. //TODO: Define an IDbSet for your Entities...
  16. #region Basic
  17. public IDbSet<TrainingRoleInfo> TrainingRoleInfos { get; set; }
  18. public IDbSet<TrainingRoleGroupInfo> TrainingRoleGroupInfos { get; set; }
  19. public IDbSet<TrainingGroupRelateRoleInfo> TrainingGroupRelateRoleInfos { get; set; }
  20. public IDbSet<TempInfo> TempInfos { get; set; }
  21. public IDbSet<StudentTipInfo> StudentHelpInfos { get; set; }
  22. public IDbSet<PortraitRemarkInfo> PortraitRemarkInfos { get; set; }
  23. public IDbSet<PhoneQuestionInfo> PhoneQuestionInfos { get; set; }
  24. public IDbSet<PhoneAnswerInfo> PhoneAnswerInfos { get; set; }
  25. #endregion Basic
  26. #region CAMP
  27. public IDbSet<CampInfo> CampInfos { get; set; }
  28. public IDbSet<CampHelpInfo> CampHelpInfos { get; set; }
  29. public IDbSet<CampGroupInfo> CampGroupInfos { get; set; }
  30. public IDbSet<GroupScoreInfo> GroupScoreInfos { get; set; }
  31. public IDbSet<GroupLogInfo> GroupLogInfos { get; set; }
  32. public IDbSet<GroupRoleInfo> GroupRoleInfos { get; set; }
  33. public IDbSet<CampSceneMapInfo> CampSceneMapInfos { get; set; }
  34. //public IDbSet<BehaviorTagInfo> BehaviorTagInfos { get; set; }
  35. public IDbSet<CampRelateGroupRoleInfo> CampRelateGroupRoleInfos { get; set; }
  36. public IDbSet<GroupPortraitInfo> GroupPortraitInfos { get; set; }
  37. //public IDbSet<> s { get; set; }
  38. #endregion CAMP
  39. /* NOTE:
  40. * Setting "Default" to base class helps us when working migration commands on Package Manager Console.
  41. * But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
  42. * pass connection string name to base classes. ABP works either way.
  43. */
  44. public IDbSet<SysAttachFile> SysAttachFiles { get; set; }
  45. public IDbSet<SysState> SysStates { get; set; }
  46. public IDbSet<SysFunction> SysFunctions { get; set; }
  47. public IDbSet<SysHelp> SysHelps { get; set; }
  48. public WeAppDbContext()
  49. : base("Default")
  50. {
  51. }
  52. /* NOTE:
  53. * This constructor is used by ABP to pass connection string defined in WeAppDataModule.PreInitialize.
  54. * Notice that, actually you will not directly create an instance of WeAppDbContext since ABP automatically handles it.
  55. */
  56. public WeAppDbContext(string nameOrConnectionString)
  57. : base(nameOrConnectionString)
  58. {
  59. }
  60. //This constructor is used in tests
  61. public WeAppDbContext(DbConnection existingConnection)
  62. : base(existingConnection, false)
  63. {
  64. }
  65. public WeAppDbContext(DbConnection existingConnection, bool contextOwnsConnection)
  66. : base(existingConnection, contextOwnsConnection)
  67. {
  68. }
  69. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  70. {
  71. base.OnModelCreating(modelBuilder);
  72. //---关闭级联删除
  73. // 禁用一对多级联删除
  74. modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
  75. // 禁用多对多级联删除
  76. modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
  77. }
  78. }
  79. }