public static string GenerateAllTables(this System.Data.Common.DbConnection connection, GeneratorBehavior generatorBehavior = GeneratorBehavior.Default) { if (connection.State != ConnectionState.Open) { connection.Open(); } var conneciontName = connection.GetType().Name.ToLower(); var tables = new List <string>(); var sql = generatorBehavior.HasFlag(GeneratorBehavior.View) ? TableSchemaSqls[conneciontName].Split("where")[0] : TableSchemaSqls[conneciontName]; using (var command = connection.CreateCommand(sql)) using (var reader = command.ExecuteReader()) { while (reader.Read()) { tables.Add(reader.GetString(0)); } } var sb = new StringBuilder(); sb.AppendLine("namespace Models { "); tables.ForEach(table => sb.Append(connection.GenerateClass( string.Format(QuerySqls[conneciontName], table), table, generatorBehavior: generatorBehavior ))); sb.AppendLine("}"); return(sb.ToString()); }