InitialHostDbBuilder.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using EntityFramework.DynamicFilters;
  2. using ShwasherSys.EntityFramework;
  3. namespace ShwasherSys.Migrations.SeedData
  4. {
  5. public class InitialHostDbBuilder
  6. {
  7. private readonly ShwasherDbContext _context;
  8. public InitialHostDbBuilder(ShwasherDbContext context)
  9. {
  10. _context = context;
  11. }
  12. public void Create()
  13. {
  14. _context.DisableAllFilters();
  15. //new DefaultDataCreator(_context).Create();
  16. //new DefaultTruncateTableSql(_context).Create();
  17. new DefaultFunctionsCreator(_context).Create();
  18. //new DefaultRoleAndUserCreator(_context).Create();
  19. //new DefaultSettingsCreator(_context).Create();
  20. //new DefaultStatesCreator(_context).Create();
  21. //new DefaultTemplateCreator(_context).Create();
  22. //new DefaultStoreLocationCreator(_context).Create();
  23. //new DefaultAppGuidsCreator(_context).Create();
  24. }
  25. }
  26. internal static class ExcuteSql
  27. {
  28. public static void DeleteTable(this ShwasherDbContext context, string tableName)
  29. {
  30. if (string.IsNullOrEmpty(tableName))
  31. {
  32. return;
  33. }
  34. var sql = $"TRUNCATE TABLE {tableName}";
  35. context.Sql(sql);
  36. }
  37. public static void Sql(this ShwasherDbContext context, string sql)
  38. {
  39. if (string.IsNullOrEmpty(sql))
  40. {
  41. return;
  42. }
  43. context.Database.ExecuteSqlCommand(sql);
  44. }
  45. }
  46. }