Пример #1
0
        public void GenerateDML(Action <string> output = null)
        {
            if (!Directory.Exists(BaseDmlFolderPath))
            {
                Directory.CreateDirectory(BaseDmlFolderPath);
            }

            if (Connection.State != System.Data.ConnectionState.Open)
            {
                Connection.Open();
            }

            if (output != null)
            {
                output("Getting source database structure...");
            }

            var schemas = new DDManager(Connection).GetSchemas(true).Where(el => el.Tables != null && el.Tables.Count > 0).ToList();

            foreach (var s in schemas)
            {
                if (s.Tables == null || s.Tables.Count == 0)
                {
                    continue;
                }

                var schemaOutputFolderPath = Path.Combine(BaseDmlFolderPath, s.Name);
                if (!Directory.Exists(schemaOutputFolderPath))
                {
                    Directory.CreateDirectory(schemaOutputFolderPath);
                }

                foreach (var t in s.Tables)
                {
                    var outputTableDmlFilePath = Path.Combine(schemaOutputFolderPath, t.Name + ".sql");
                    GenerateDML(t, outputTableDmlFilePath, output);
                }
            }

            if (output != null)
            {
                output("Successfully generated DML.");
            }
        }