What We Learn
We will be dipping our toes in C# programming, creating custom transformations to be used in conjunction with source mappings.
Preparations
Open the Scripting subdirectory of the D♯ Engine installation in Visual Studio Code. Search for the text string columnvaluetransformation and you will find a number of C# classes that implement a function for transforming an incoming value to something else. These transformations can be used in the mapping files in the Transformation column instead of a hardcoded expression. To use a custom transformation, write its name preceded with a “!” in the Transformation cell of the mapping file. When generating the hash procedure, the !name will be swapped for whatever SQL code the function will generate.
Examine the classes to get the hang of it. Main point: the pSource variable will be the content of the column to which the transformation is applied.
In the Tutorial 10\Code folder you can find two more C# source files. You can use those as examples, or make your own.
Under Scripting/Users, create a new folder and call it someusername. Either copy one or both of the example source files into the directory, or create your own transformation using Visual Studio Code. Save and run D♯ Engine.
Mapping
Select any existing mapping file from the Tutorial 10 directory and open it in D♯ Engine. Open the Languages pane, select a Transformation to your liking (your new transformation should be available to select), and drag it on top of the row that you want to apply it to. Save the mappings and refresh. Inspect the hashing procedure affected to see how the transformation is applied.
Deploy the Changes And Try It Out
Deploy the class for which the mappings have changed. Run a Tutorial command that loads data that is affected by the transformation and view the results.