InitMallTable.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Microsoft.AspNetCore.Hosting;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Microsoft.Extensions.Hosting;
  4. using SqlSugar.IOC;
  5. using ZR.Mall.Model;
  6. namespace ZR.Mall
  7. {
  8. /// <summary>
  9. /// 初始化表
  10. /// </summary>
  11. public static class InitMallTable
  12. {
  13. public static void InitDb(this IServiceCollection services, IWebHostEnvironment environment)
  14. {
  15. var db = DbScoped.SugarScope.GetConnection("1");
  16. var options = App.OptionsSetting;
  17. if (!options.InitDb) return;
  18. if (environment.IsDevelopment())
  19. {
  20. db.CodeFirst.InitTables(typeof(Product));
  21. db.CodeFirst.InitTables(typeof(ProductSpec));
  22. db.CodeFirst.InitTables(typeof(Skus));
  23. db.CodeFirst.InitTables(typeof(Category));
  24. db.CodeFirst.InitTables(typeof(Brand));
  25. db.CodeFirst.InitTables(typeof(OMSOrder));
  26. db.CodeFirst.InitTables(typeof(OMSOrderItem));
  27. db.CodeFirst.InitTables(typeof(MMSUserAddress));
  28. db.CodeFirst.InitTables(typeof(SpecTemplate));
  29. }
  30. }
  31. }
  32. }