public SmoScriptingContext(IDbConnection connection, SmoObjectMetadata metadata) { Connection = new ServerConnection((SqlConnection)connection); Server = new Server(Connection); Database = Server.Databases[Connection.DatabaseName]; Metadata = metadata; ScriptDatabaseContext = true; }
private string Script(IDbConnection connection, string schema, string name) { var metadata = new SmoObjectMetadata(schema, name); metadata.Initialize(connection); var context = new SmoScriptingContext(connection, metadata); SmoScriptableObject obj = _objectFactory.Create(context); StringCollection batches = obj.Script(context); var builder = new StringBuilder(); foreach (string batch in batches) { builder.Append(batch); } string result = builder.ToString(); return(result); }