我正在从 bimlscript.com 学习 BIML,并在此处完成了以下步骤:http: //www.bimlscript.com/Walkthrough/Details/3111。我让它为本地主机上的数据库创建一个新表。如何使用 BIML Express 运行它?Visual Studio 的 BIMLExpress 菜单只提供生成 SSIS 包的选项。
1 回答
Generate SSIS package or Check for errors both evaluate Biml and BimlScript.
As a quick summary of the article, it shows to you model or describe the relational artifacts (database/schema/table) with Biml. This can be done manually or via reverse engineering with GetDatabaseSchema.
The thing is, these artifacts are all in-memory. As soon as the compiler is done Generating SSIS package or Checking for errors, they go away. What you are looking to do is have a button or something BimlExpress to "Make database objects."
That doesn't exist directly - but you can build all the tooling you need with more BimlScript. You can inspect the evaluated Biml by using tiering and evaluating the RootNode's biml
The referenced article doesn't show using the GetDropAndCreateDdl
method. Invoking that against in memory relational objects (database/schema/table) will translate the Biml to a SQL definition.
What you need to figure out is whether you want to run the SQL every time, just generate the SQL text files or make an SSIS package that you then execute to run the SQL commands.
For example, this bit of Biml will generate to the preview window all the drop and create statements you need.
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
foreach(var db in RootNode.Databases)
{
WriteLine(db.GetDropAndCreateDdl());
}
foreach(var schema in RootNode.Schemas)
{
WriteLine(schema.GetDropAndCreateDdl());
}
foreach(var table in RootNode.Tables)
{
WriteLine(table.GetDropAndCreateDdl());
}
#>
</Biml>
If I wanted to save to file, replace the WriteLine calls with System.IO.File.WriteAllText
If you want to fire off those as SQL Commands, then it's going to be a bit more complex as you'd need to instantiate the Connection Manager associated to the Database and then run the ddl.