如何使用 Pomelo.EntityFrameworkCore.MySql 获取所有数据表名
本文发布于 3 年前,部分内容可能已经失去参考价值。
private static List<string> GetTableNames(DbContext context)
{
context.Database.OpenConnection();
var connection = context.Database.GetDbConnection();
using var command = connection.CreateCommand();
command.CommandText = @"SELECT `TABLE_NAME`
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE();";
var tableNames = new List<string>();
using var reader = command.ExecuteReader();
while (reader.Read())
{
tableNames.Add((string)reader["TABLE_NAME"]);
}
return tableNames;
}
l
转自
lauxjpn
3 年前
可能相关的内容