Is it possible to remove column from the GetTableSql() in BIML

Viewed 115

I use the GetTableSql() function in BIML a lot, but I often need to remove some columns from this function before it executes. Is this possible?

1 Answers

You'd have to write your own Extension method to do so. Looking through the code, you might be better off just scrubbing the column(s) from results of the method call - it just depends on what you're looking to do.

The current GetTableSql method is an extension method that chains a call to EmitTableScript which in turn calls a number of methods to build out the returning SQL. At least in the BimlStudio product, EmitTableScript is in Varigence.Biml.CoreLowerer.Capabilities.TableToPackageLowerer class in BimlExtensions.dll

After a bit more thinking, what might be an even better, less support headache would be to create a clone of the table node and then remove the columns you don't want.

Code approximately

var table0 = this.RootNode.Tables[0];
var tablePrime = table0;

// I don't have a biml project handy so this section is a guess
tablePrime.Columns.Clear();
// Might be AddRange if this method exists
// Remove all the columns that start with ignore, as an example of filtering columns
tablePrime.Columns.Add(table0.Columns.Where(x => !x.name.StartsWith("ignore"));

// end guess block    
var sql = tablePrime.GetTableSql();
Related