IwbDbContext.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Data.Common;
  2. using System.Data.Entity;
  3. using System.Data.Entity.ModelConfiguration.Conventions;
  4. using ContractService.Authorization.Roles;
  5. using ContractService.Authorization.Users;
  6. using ContractService.BaseInfo;
  7. using ContractService.Client;
  8. using ContractService.LawFirm;
  9. using ContractService.Lawyer;
  10. using ContractService.LegalCase;
  11. using ContractService.LegalContract;
  12. using ContractService.MultiTenancy;
  13. using IwbZero.EntityFramework;
  14. namespace ContractService.EF
  15. {
  16. public class ContractServiceDbContext : IwbZeroDbContext<Tenant, Role, User>
  17. {
  18. //TODO: Define an IDbSet for your Entities...
  19. /* NOTE:
  20. * Setting "Default" to base class helps us when working migration commands on Package Manager Console.
  21. * But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
  22. * pass connection string name to base classes. ABP works either way.
  23. */
  24. /* ------------------------------------------------------------------------- */
  25. public IDbSet<LawFirmInfo> LawFirmInfos { get; set; }
  26. public IDbSet<LawyerInfo> LawyerInfos { get; set; }
  27. public IDbSet<LegalServiceType> LegalServiceTypes { get; set; }
  28. public IDbSet<LegalCaseInfo> LegalServiceInfos { get; set; }
  29. public IDbSet<LegalCaseNoteInfo> LegalServiceNoteInfos { get; set; }
  30. public IDbSet<LegalContractInfo> LegalContractInfos { get; set; }
  31. public IDbSet<LegalContractSupplementInfo> LegalContractSupplementInfos { get; set; }
  32. public IDbSet<LegalContractContentInfo> LegalContractContentInfos { get; set; }
  33. public IDbSet<LegalContractKeyPointInfo> LegalContractKeyPointInfos { get; set; }
  34. public IDbSet<LegalContractNoteInfo> LegalContractNoteInfos { get; set; }
  35. public IDbSet<LawyerRelatedInfo> LawyerRelatedInfos { get; set; }
  36. public IDbSet<ClientCompanyInfo> ClientCompanyInfos { get; set; }
  37. public IDbSet<OrganizationInfo> ClientOrganizationInfos { get; set; }
  38. public IDbSet<ClientStaffInfo> ClientStaffInfos { get; set; }
  39. public IDbSet<StaffRelatedInfo> StaffRelateInfos { get; set; }
  40. public IDbSet<SysAttachFile> SysAttachFiles { get; set; }
  41. public IDbSet<SysState> SysStates { get; set; }
  42. public IDbSet<SysFunction> SysFunctions { get; set; }
  43. public IDbSet<SysHelp> SysHelps { get; set; }
  44. public IDbSet<SysQuery> SysQueryInfos { get; set; }
  45. public ContractServiceDbContext()
  46. : base("Default")
  47. {
  48. }
  49. /* NOTE:
  50. * This constructor is used by ABP to pass connection string defined in ContractServiceDataModule.PreInitialize.
  51. * Notice that, actually you will not directly create an instance of ContractServiceDbContext since ABP automatically handles it.
  52. */
  53. public ContractServiceDbContext(string nameOrConnectionString)
  54. : base(nameOrConnectionString)
  55. {
  56. }
  57. //This constructor is used in tests
  58. public ContractServiceDbContext(DbConnection existingConnection)
  59. : base(existingConnection, false)
  60. {
  61. }
  62. public ContractServiceDbContext(DbConnection existingConnection, bool contextOwnsConnection)
  63. : base(existingConnection, contextOwnsConnection)
  64. {
  65. }
  66. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  67. {
  68. base.OnModelCreating(modelBuilder);
  69. //---关闭级联删除
  70. // 禁用一对多级联删除
  71. modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
  72. // 禁用多对多级联删除
  73. modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
  74. }
  75. }
  76. }