Dynamic Columns are similar to Calculated Columns except that you write the code for Dynamic Columns as a C# Property in a Class file.
Dynamic Columns allow you to use the full .NET Framework and allow you to create complex data transformations.
In it's most basic form a Dynamic Column is simply the result of a C# Property getter the name of the Property becomes the column name and the result is calculated at runtime during Data Load.
public string MyNewValue
{
get { return "myValue"; }
}
The Dynamic Columns class is created just before the Data is loaded for Data Source (A), this single instance is valid for the duration of the load and BeginRow() is called for each row giving you a chance to set your property values.
Returning False from BeginRow() will filter the row from the result.
The Start() method allows you set any initialisation you need before the rows are processed.
To enable Dynamic Columns press the Dynamic Columns button on the toolbar and click Enable Dynamic Columns this will create the initial Dynamic Columns class template.
This example for Dynamic Columns takes an embedded Xml document from the source data DescriptionLines and extracts the line items into a simple string value and prepends the product name.
<Lines>
<Line>Line 1 Description</Line>
<Line>Line 2 Description</Line>
</Lines>
This is an example of Dynamic Columns enabling advanced Data Transformation capabilities that are not trivial.
using System.Xml;
partial class DataSourceRowOverride : Simego.DataSync.DynamicColumns.DataSourceRowInternal
{
public string ProductDescription { get; set; }
public override bool BeginRow()
{
ProductDescription = Name;
XmlDocument doc = new XmlDocument();
doc.LoadXml(DescriptionLines);
foreach(XmlNode line in doc.SelectNodes("//Line"))
{
ProductDescription += string.Format(" - {0}", line.InnerText);
}
return true;
}
}
To remove a single dynamic column, simply delete the Property Declaration from the Class.
To remove all Dynamic Columns, simply delete all the code from the Dynamic Columns window.
Adding a public method to the Dynamic Columns class makes it available to Calculated Columns.
If you create a function you need to call multiple times, it is preferred to create the function in Dynamic Columns and use Calculated columns to call it.