WePlatformDbContext.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System.Data.Common;
  2. using System.Data.Entity;
  3. using System.Data.Entity.ModelConfiguration.Conventions;
  4. using WePlatform.Authorization.Roles;
  5. using WePlatform.Authorization.Users;
  6. using WePlatform.BaseInfo;
  7. using WePlatform.MultiTenancy;
  8. using IwbZero.EntityFramework;
  9. using WePlatform.ThirdPartySystem;
  10. using WePlatform.WeBase;
  11. using WePlatform.WeLib;
  12. using WePlatform.WeLib.Knowledge;
  13. using WePlatform.WeModel;
  14. namespace WePlatform.EF
  15. {
  16. public class WePlatformDbContext : IwbZeroDbContext<Tenant, Role, User>
  17. {
  18. //TODO: Define an IDbSet for your Entities...
  19. #region WE
  20. public IDbSet<ThirdPartySystemInfo> ThirdPartySystemInfos { get; set; }
  21. public IDbSet<SceneCategoryInfo> SceneCategoryInfos { get; set; }
  22. public IDbSet<BehaviorRoleInfo> BehaviorRoleInfos { get; set; }
  23. public IDbSet<RoleRelateCategoryInfo> RoleRelateCategoryInfos { get; set; }
  24. public IDbSet<EnvironResourceInfo> EnvironResourceInfos { get; set; }
  25. public IDbSet<EnvironResourceRelatedInfo> EnvironResourceRelatedInfos { get; set; }
  26. public IDbSet<EngineInfo> EngineInfos { get; set; }
  27. public IDbSet<EngineModelInfo> EngineModelInfos { get; set; }
  28. public IDbSet<EvalModelInfo> EvalModelInfos { get; set; }
  29. public IDbSet<EvalTargetInfo> EvalTargetInfos { get; set; }
  30. public IDbSet<EvalReportTemplateInfo> EvalReportTemplateInfos { get; set; }
  31. public IDbSet<EngineComponentInfo> EngineComponentInfos { get; set; }
  32. public IDbSet<GuideInfo> GuideInfos { get; set; }
  33. public IDbSet<GuideRelatedInfo> GuideRelatedInfos { get; set; }
  34. public IDbSet<KnowledgeInfo> KnowledgeInfos { get; set; }
  35. public IDbSet<EmergencyPlanInfo> EmergencyPlanInfos { get; set; }
  36. public IDbSet<KnowledgeRelatePlanInfo> KnowledgeRelatePlanInfos { get; set; }
  37. public IDbSet<EmergencyPlanContentInfo> EmergencyPlanContentInfos { get; set; }
  38. public IDbSet<EmergencyResourceInfo> EmergencyResourceInfos { get; set; }
  39. public IDbSet<BehaviorInfo> BehaviorInfos { get; set; }
  40. public IDbSet<BehaviorRelateRoleInfo> BehaviorRelateRoleInfos { get; set; }
  41. public IDbSet<BehaviorKnowledgeInfo> BehaviorKnowledgeInfos { get; set; }
  42. public IDbSet<SceneInfo> SceneInfos { get; set; }
  43. public IDbSet<SceneBehaviorInfo> SceneBehaviorInfos { get; set; }
  44. public IDbSet<SceneFlowInfo> SceneFlowInfos { get; set; }
  45. public IDbSet<PackageInfo> PackageInfos { get; set; }
  46. public IDbSet<PackageXmlInfo> PackageXmlInfos { get; set; }
  47. #endregion
  48. /* NOTE:
  49. * Setting "Default" to base class helps us when working migration commands on Package Manager Console.
  50. * But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
  51. * pass connection string name to base classes. ABP works either way.
  52. */
  53. public IDbSet<SysAttachFile> SysAttachFiles { get; set; }
  54. public IDbSet<SysState> SysStates { get; set; }
  55. public IDbSet<SysFunction> SysFunctions { get; set; }
  56. public IDbSet<SysHelp> SysHelps { get; set; }
  57. public WePlatformDbContext()
  58. : base("Default")
  59. {
  60. }
  61. /* NOTE:
  62. * This constructor is used by ABP to pass connection string defined in WePlatformDataModule.PreInitialize.
  63. * Notice that, actually you will not directly create an instance of WePlatformDbContext since ABP automatically handles it.
  64. */
  65. public WePlatformDbContext(string nameOrConnectionString)
  66. : base(nameOrConnectionString)
  67. {
  68. }
  69. //This constructor is used in tests
  70. public WePlatformDbContext(DbConnection existingConnection)
  71. : base(existingConnection, false)
  72. {
  73. }
  74. public WePlatformDbContext(DbConnection existingConnection, bool contextOwnsConnection)
  75. : base(existingConnection, contextOwnsConnection)
  76. {
  77. }
  78. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  79. {
  80. base.OnModelCreating(modelBuilder);
  81. //---关闭级联删除
  82. // 禁用一对多级联删除
  83. modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
  84. // 禁用多对多级联删除
  85. modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
  86. }
  87. }
  88. }