public virtual string SerializeDbMetadata(Func <string, bool> tableNamePredicate = null) { tableNamePredicate = tableNamePredicate ?? (x => true); var tables = this.DbInspector .GetTableNames(true) .Select(x => this.Factory.CreateTableInspector(this.Connection, x).GetTable()) .Where(x => tableNamePredicate(x.Name)) .ToList(); foreach (var table in tables) { table.ForeignKeys = table.ForeignKeys .OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase) .ToList(); table.Indexes = table.Indexes .OrderBy(x => x.Name, StringComparer.InvariantCultureIgnoreCase) .ToList(); } var dbMold = new DbMold { DbProviderName = this.Factory.DbProviderName, Tables = tables .Select(x => x.CloneTable(false)) .ToList(), }; var json = DbUtils.FineSerializeToJson(dbMold); return(json); }
public DbMold ConvertDb(DbMold originDb, IReadOnlyDictionary <string, string> options = null) { var result = new DbMold { DbProviderName = this.Factory.DbProviderName, Tables = originDb .Tables .Select(x => this.ConvertTable(x, originDb.DbProviderName)) .ToList(), }; return(result); }
public static string ConvertDbToJson( this IDbConverter dbConverter, DbMold originDb, IReadOnlyDictionary <string, string> options = null) { if (dbConverter == null) { throw new ArgumentNullException(nameof(dbConverter)); } var convertedDb = dbConverter.ConvertDb(originDb, options); var json = DbUtils.FineSerializeToJson(convertedDb); return(json); }