ExecuteSql.cs 648 B

12345678910111213141516171819202122232425
  1. using WePlatform.EF;
  2. namespace WePlatform.SeedData
  3. {
  4. public static class ExecuteSql
  5. {
  6. public static void TruncateTable(this WePlatformDbContext context, string tableName)
  7. {
  8. if (string.IsNullOrEmpty(tableName))
  9. {
  10. return;
  11. }
  12. var sql = $"TRUNCATE TABLE {tableName}";
  13. context.Sql(sql);
  14. }
  15. public static void Sql(this WePlatformDbContext context, string sql)
  16. {
  17. if (string.IsNullOrEmpty(sql))
  18. {
  19. return;
  20. }
  21. context.Database.ExecuteSqlCommand(sql);
  22. }
  23. }
  24. }