I have created a HelperFunctions.cs file containing the following:

using Varigence.Languages.Biml.Table;
public static class HelperFunctions
{
  public static string GetDisplayTableName(AstTableNode table) 
  {
    return table.GetTag("DatabaseName").ToUpper() + "_" + table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper();

  }

}

However it does not recognise GetTag() and throws the error :

'AstTableNode' does not contain a definition for 'GetTag' and no accessible extension method 'GetTag' accepting a first argument of type 'AstTableNode' could be found (are you missing a using directive or an assembly reference?). What do I need to add to make this work? Thanks Jon

1

There are 1 answers

7
billinkc On BEST ANSWER

A static method needs to have the parameter prefixed with this

SO_63828312.cs

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Varigence.Biml.Extensions;
using Varigence.Languages.Biml.Table;
public static class HelperFunctions
{
    public static string GetDisplayTableName(this AstTableNode table)
    {
        return table.GetTag("DatabaseName").ToUpper() + "_" + table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper();

    }

}

My static Biml defines a table, which needs a schema, which needs a database, which needs a connection. All of that to get us to a table that has an AnnotationType of Tag with a value of AW.

SO_63828312.T0.biml

<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Connections>
        <OleDbConnection ConnectionString="Data Source=localhost\dev2017;Initial Catalog=tempdb;Provider=SQLNCLI11.1;Integrated Security=SSPI;Auto Translate=False;Packet Size=32767;" Name="AdventureWorks" />
    </Connections>
    <Databases>
        <Database Name="AW" ConnectionName="AdventureWorks" />
    </Databases>
    <Schemas>
        <Schema DatabaseName="AW" Name="dbo" />
    </Schemas>
    <Tables>
        <Table Name="foo" SchemaName="AW.dbo">
            <Annotations>
                <Annotation Tag="DatabaseName" AnnotationType="Tag">AW</Annotation>
            </Annotations>
            <Columns>
                <Column Name="Col1" DataType="Int32"></Column>
            </Columns>
        </Table>
    </Tables>
</Biml>

Tier 1 execution. This begins our dynamic tiering. Since there's only one, I don't explicitly give it one but if you have multiple tiers, you'd want to provide a directive.

Here I enumerate my Tables collection (defined in a preceding tier) and for each table I find, I write the table name and the tag value

SO_63828312.T1.biml

<#@ code file="SO_63828312.cs" #>


<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<#
string template =  "<!-- {0}|{1} -->";
foreach(var t in this.RootNode.Tables)
{
    WriteLine(string.Format(template, t.Name, t.GetDisplayTableName()));
}
#>
</Biml>

Emitted Biml