Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Level Up Your Biml:
Best Practices and
Coding Techniques
Cathrine Wilhelmsen · SQLBits · Feb 24th 2018
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Session Description
Is your Biml solution starting to remind you of a...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Cathrine Wilhelmsen
@cathrinew cathrinew.net
Data Warehouse & Busines...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
You…
…?
Know basic Biml and BimlScript
Created a staging environment ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
…the next 60 minutes…
Practical Biml Coding C# Classes and Methods
Co...
Biml and
BimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Biml vs. BimlScript
XML Language
"Just plain text"
Generate, control ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Biml
Biml is an XML language – it's just plain text
Easy to read and ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Generating Biml
You can use any tool to generate Biml for you:
• Text...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Extend Biml with C# or VB code blocks
Import database structure and m...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlScript Code Blocks
<# … #> Control Block (Control logic)
<#= … #>...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlScript Syntax
<# var con = SchemaManager.CreateConnectionNode(......
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlScript Syntax: Import metadata
<# var con = SchemaManager.CreateC...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlScript Syntax: Loop over tables
<# var con = SchemaManager.Create...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlScript Syntax: Replace static values
<# var con = SchemaManager.C...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
How does it work?
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Yes, but how does it work?
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Yes, but how does it actually work?
<# foreach (var table in metadata...
Biml Tools
Comparison
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
What do you need?
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlExpress
Free add-in for Visual Studio
Code editor with syntax hig...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlOnline
Free browser-based Biml editor
Code editor with Biml and C...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
BimlStudio
Licensed full-featured development environment for Biml
Vi...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Biml Tools Comparison
Licensed
IDE replaces VS
Full Automation
Free
B...
Code
Management
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Don't Repeat Yourself
Centralize and reuse code
Update code once in o...
Tiered Biml Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
What are Tiered Biml Files?
Think of tiers as stacked layers or seque...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files
Split Biml code in multiple files to:
• Solve logic...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files
Biml is compiled from lowest to highest tier
• Biml...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Load Packages
Master...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Tiered Biml Files: Behind the Scenes
Connections
Admin
Source
Destina...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
How do you use Tiered Biml Files?
1. Create Biml files with specified...
Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Include Files
Include common code in multiple files and projects
Can ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Include Files
Global Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Global Include Files
Use the global directive
<#@ global #>
Use inste...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Global Include Files
Specify directive attributes to control global i...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Global Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Global Include Files
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
How do you use Global Include Files?
1. Create Global Include File
2....
CallBimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
Works like a parameterized include (or stored procedur...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScript
CallBimlScriptWithOutput
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput: Callee
Callee specifies parameters and cust...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput: Caller
Caller creates, passes and uses cust...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
CallBimlScriptWithOutput
use CustomOutput
DEMO
Code Management
Practical
Biml Coding
Annotations and ObjectTags
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Annotations and ObjectTags
Annotations and ObjectTags are Key / Value...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Annotations
Create annotations:
<OleDbConnection Name="Dest" Connecti...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
ObjectTags
Create ObjectTags:
RootNode.ObjectTag["Filter"] =
new List...
LINQ
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ (Language-Integrated Query)
One language to query:
SQL Server Da...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ Extension Methods
Sort
OrderBy, ThenBy
Filter
Where, OfType
Grou...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ Extension Methods Example
var numConnections = RootNode.Connecti...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ Extension Methods Example
foreach (var table in RootNode.Tables....
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
"A lambda expression is an anonymous
function that...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
…huh? o_O
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
table => table.Name == "Product"
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
table => table.Name == "Product"
The arrow is the ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
table => table.Name == "Product"
Input parameter i...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
table => table.Name == "Product"
Expression is on ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Lambda Expressions
table => table.Name == "Product"
For each object i...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ and Lambda
Chain LINQ Methods and use Lambda Expressions for
sim...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Filter collections
Where()
Returns the filtered collection with...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Sort collections
OrderBy()
Returns the collection sorted by key...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Sort collections
OrderByDescending()
Returns the collection sor...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Sort collections
Reverse()
Returns the collection sorted in rev...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Group collections
GroupBy()
Returns a collection of key-value p...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Aggregate collections
Count()
Returns the number of elements in...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Aggregate collections
Sum()
Returns the sum of the (numeric) va...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Aggregate collections
Min()
Returns the minimum value of the (n...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Check collections
All()
Returns true if all elements in the col...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Check collections
Contains()
Returns true if collection contain...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Get elements
First()
Returns the first element in the collectio...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Get elements
Last()
Returns the last element in the collection ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Get elements
ElementAt()
Returns the element in the collection ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Project collections
Select()
Creates a new collection from one ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
LINQ: Project collections
SelectMany()
Creates a new collection from ...
DEMO
Practical
Biml Coding
Classes
and Methods
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
C# Classes and Methods
BimlScript and LINQ not enough?
Need to reuse ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
C# Classes and Methods
public static class Utilities {
public static ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
C# Classes and Methods: Class
public static class Utilities {
public ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
C# Classes and Methods: Method
public static class Utilities {
public...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
C# Classes and Methods: Logic
public static class Utilities {
public ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Where do you put your C# code?
Code Blocks
<#+ ... #>
Code Files
<#@ ...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Code Blocks vs. Code Files
Code Blocks
• Used when logic is specific ...
Extension Methods
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Extension Methods
"Make it look like the method belongs to
an object ...
DEMO
C# Classes
and Methods
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
…the past 60 minutes…
Practical Biml Coding C# Classes and Methods
Co...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Feedback
How can speakers and
SQLBits improve?
Community
Where can yo...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
Get things done
Start small
Start simple
Start with ugly code
Keep go...
Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net
@cathrinew
cathrinew.net
hi@cathrinew.net
Biml resources and referenc...
Upcoming SlideShare
Loading in …5
×

of

Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 1 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 2 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 3 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 4 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 5 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 6 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 7 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 8 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 9 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 10 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 11 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 12 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 13 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 14 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 15 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 16 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 17 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 18 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 19 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 20 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 21 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 22 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 23 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 24 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 25 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 26 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 27 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 28 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 29 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 30 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 31 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 32 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 33 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 34 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 35 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 36 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 37 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 38 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 39 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 40 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 41 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 42 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 43 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 44 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 45 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 46 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 47 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 48 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 49 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 50 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 51 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 52 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 53 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 54 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 55 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 56 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 57 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 58 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 59 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 60 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 61 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 62 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 63 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 64 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 65 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 66 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 67 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 68 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 69 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 70 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 71 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 72 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 73 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 74 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 75 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 76 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 77 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 78 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 79 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 80 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 81 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 82 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 83 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 84 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 85 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 86 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 87 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 88 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 89 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 90 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 91 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 92 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 93 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 94 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 95 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 96 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 97 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 98 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 99 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 100 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 101 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 102 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 103 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 104 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 105 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 106 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 107 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 108 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 109 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 110 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 111 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 112 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 113 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 114 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 115 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 116 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 117 Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018) Slide 118
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0 Likes

Share

Download to read offline

Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018)

Download to read offline

Level Up Your Biml: Best Practices and Coding Techniques (Presented at SQLBits on February 24th 2018)

  • Be the first to like this

Level Up Your Biml: Best Practices and Coding Techniques (SQLBits 2018)

  1. 1. Level Up Your Biml: Best Practices and Coding Techniques Cathrine Wilhelmsen · SQLBits · Feb 24th 2018
  2. 2. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Session Description Is your Biml solution starting to remind you of a bowl of tangled spaghetti code? Good! That means you are solving real problems while saving a lot of time. The next step is to make sure that your solution does not grow too complex and confusing – you do not want to waste all that saved time on future maintenance! Attend this session for an overview of Biml best practices and coding techniques. Learn how to centralize and reuse code with Include files and the CallBimlScript method. Make your code easier to read and write by utilizing LINQ (Language-Integrated Queries). Share code between files by using Annotations and ObjectTags. And finally, if standard Biml is not enough to solve your problems, you can create your own C# helper classes and extension methods to implement custom logic. Start improving your code today and level up your Biml in no time!
  3. 3. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Cathrine Wilhelmsen @cathrinew cathrinew.net Data Warehouse & Business Intelligence Consultant
  4. 4. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net You… …? Know basic Biml and BimlScript Created a staging environment using Biml Created a metadata-driven Biml framework
  5. 5. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net …the next 60 minutes… Practical Biml Coding C# Classes and Methods Code Management
  6. 6. Biml and BimlScript
  7. 7. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Biml vs. BimlScript XML Language "Just plain text" Generate, control and manipulate Biml with C#
  8. 8. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Biml Biml is an XML language – it's just plain text Easy to read and write – but can be verbose You probably don't want to write 50000 lines of Biml code manually...?
  9. 9. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Generating Biml You can use any tool to generate Biml for you: • Text editor macros • Excel • PowerShell • T-SQL …but the recommended tool is BimlScript :)
  10. 10. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Extend Biml with C# or VB code blocks Import database structure and metadata Loop over tables and columns Expressions replace static values Allows you to generate, control and manipulate Biml code What is BimlScript?
  11. 11. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlScript Code Blocks <# … #> Control Block (Control logic) <#= … #> Text Block (Returns string) <#@ … #> Directive (Compiler instructions) <#+ … #> Class Block (Create C# classes) <#* … *#> Comment Block (Comments)
  12. 12. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlScript Syntax <# var con = SchemaManager.CreateConnectionNode(...); #> <# var metadata = con.GetDatabaseSchema(); #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Packages> <# foreach (var table in metadata.TableNodes) { #> <Package Name="Load_<#=table.Name#>"></Package> <# } #> </Packages> </Biml>
  13. 13. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlScript Syntax: Import metadata <# var con = SchemaManager.CreateConnectionNode(...); #> <# var metadata = con.GetDatabaseSchema(); #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Packages> <# foreach (var table in metadata.TableNodes) { #> <Package Name="Load_<#=table.Name#>"></Package> <# } #> </Packages> </Biml>
  14. 14. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlScript Syntax: Loop over tables <# var con = SchemaManager.CreateConnectionNode(...); #> <# var metadata = con.GetDatabaseSchema(); #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Packages> <# foreach (var table in metadata.TableNodes) { #> <Package Name="Load_<#=table.Name#>"></Package> <# } #> </Packages> </Biml>
  15. 15. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlScript Syntax: Replace static values <# var con = SchemaManager.CreateConnectionNode(...); #> <# var metadata = con.GetDatabaseSchema(); #> <Biml xmlns="http://schemas.varigence.com/biml.xsd"> <Packages> <# foreach (var table in metadata.TableNodes) { #> <Package Name="Load_<#=table.Name#>"></Package> <# } #> </Packages> </Biml>
  16. 16. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net How does it work?
  17. 17. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Yes, but how does it work?
  18. 18. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Yes, but how does it actually work? <# foreach (var table in metadata.TableNodes) { #> <Package Name="Load_<#=table.Name#>"></Package> <# } #> <Package Name="Load_Customer"></Package> <Package Name="Load_Product"></Package> <Package Name="Load_Sales"></Package>
  19. 19. Biml Tools Comparison
  20. 20. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net What do you need?
  21. 21. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlExpress Free add-in for Visual Studio Code editor with syntax highlighting and Biml Intellisense Preview expanded / compiled Biml http://varigence.com/bimlexpress
  22. 22. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlOnline Free browser-based Biml editor Code editor with Biml and C# Intellisense Reverse-engineer from SSIS to Biml http://bimlonline.com
  23. 23. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net BimlStudio Licensed full-featured development environment for Biml Visual designer and metadata modeling Full-stack automation and transformers http://varigence.com/bimlstudio
  24. 24. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Biml Tools Comparison Licensed IDE replaces VS Full Automation Free Biml intellisense Preview Pane Free Full intellisense Package Import
  25. 25. Code Management
  26. 26. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Don't Repeat Yourself Centralize and reuse code Update code once in one file 1. Tiered Biml Files 2. Include Files 3. CallBimlScript
  27. 27. Tiered Biml Files
  28. 28. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net What are Tiered Biml Files? Think of tiers as stacked layers or sequential steps Tier (Layer) 1 Tier 0 Tier (Layer) 2 Tier (Step) 1 Tier (Step) 2
  29. 29. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files Split Biml code in multiple files to: • Solve logical dependencies • Build solutions in multiple steps Specify tier per file by using the template directive: <#@ template tier="2" #>
  30. 30. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files Biml is compiled from lowest to highest tier • Biml files are implicitly tier 0 • BimlScript files are implicitly tier 1 In each tier, objects are added in-memory to RootNode Higher tiers call RootNode to use objects from lower tiers
  31. 31. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Databases Schemas Tables Packages
  32. 32. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Databases Schemas Tables Packages
  33. 33. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages
  34. 34. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages
  35. 35. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages
  36. 36. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales
  37. 37. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales
  38. 38. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales
  39. 39. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master
  40. 40. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Load Packages Master Package Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master
  41. 41. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Tiered Biml Files: Behind the Scenes Connections Admin Source Destination Databases Schemas Tables Packages Load_Customer Load_Product Load_Sales Master
  42. 42. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net How do you use Tiered Biml Files? 1. Create Biml files with specified tiers 2. Select all the tiered Biml files 3. Right-click and click Generate SSIS Packages 1 2 3
  43. 43. Include Files
  44. 44. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Include Files Include common code in multiple files and projects Can include many file types: .biml .txt .sql .cs Use the include directive <#@ include file="CommonCode.biml" #> The directive will be replaced by the included file Works like an automated Copy & Paste
  45. 45. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Include Files
  46. 46. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Include Files
  47. 47. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Include Files
  48. 48. Global Include Files
  49. 49. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Global Include Files Use the global directive <#@ global #> Use instead of adding include directive to all files to • Create global variables • Include code files • Make VB default language
  50. 50. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Global Include Files Specify directive attributes to control global include files <#@ global order="1" location="top" active="true" applytocallbimlscript="false" #>
  51. 51. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Global Include Files
  52. 52. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Global Include Files
  53. 53. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net How do you use Global Include Files? 1. Create Global Include File 2. Select Biml files and Global Include File 3. Right-click and click Generate SSIS Packages 1 2 3
  54. 54. CallBimlScript
  55. 55. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript Works like a parameterized include (or stored procedure) File to be called (callee) specifies accepted parameters: <#@ property name="Parameter" type="String" #> File that calls (caller) passes parameters: <#=CallBimlScript("Callee.biml", Parameter)#>
  56. 56. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript
  57. 57. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript
  58. 58. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript
  59. 59. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript
  60. 60. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScript
  61. 61. CallBimlScriptWithOutput
  62. 62. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput: Callee Callee specifies parameters and custom output: <#@ property name="Parameter" type="String" #> <# CustomOutput.BimlComment = "Comment"; #>
  63. 63. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput: Caller Caller creates, passes and uses custom output: <# dynamic outObj; #> <#=CallBimlScriptWithOutput("Callee.biml", out outObj)#> <#=outObj.BimlComment#>
  64. 64. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput
  65. 65. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput
  66. 66. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput
  67. 67. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput
  68. 68. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net CallBimlScriptWithOutput use CustomOutput
  69. 69. DEMO Code Management
  70. 70. Practical Biml Coding
  71. 71. Annotations and ObjectTags
  72. 72. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Annotations and ObjectTags Annotations and ObjectTags are Key / Value pairs Used to store and pass metadata between Biml files Annotations: String / String ObjectTags: String / Object
  73. 73. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Annotations Create annotations: <OleDbConnection Name="Dest" ConnectionString="…"> <Annotations> <Annotation Tag="Schema">stg</Annotation> </Annotations> </OleDbConnection> Use annotations: RootNode.OleDbConnections["Dest"].GetTag("Schema");
  74. 74. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net ObjectTags Create ObjectTags: RootNode.ObjectTag["Filter"] = new List<string>{"Product","ProductCategory"}; Use ObjectTags: var FilterList = (List<string>)RootNode.ObjectTag["Filter"];
  75. 75. LINQ
  76. 76. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ (Language-Integrated Query) One language to query: SQL Server Databases Datasets Collections Two ways to write queries: SQL-ish Syntax Extension Methods
  77. 77. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ Extension Methods Sort OrderBy, ThenBy Filter Where, OfType Group GroupBy Aggregate Count, Sum Check Collections All, Any, Contains Get Elements First, Last, ElementAt Project Collections Select, SelectMany
  78. 78. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ Extension Methods Example var numConnections = RootNode.Connections.Count() foreach (var table in RootNode.Tables.Where(…)) if (RootNode.Packages.Any(…))
  79. 79. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ Extension Methods Example foreach (var table in RootNode.Tables.Where(…)) if (RootNode.Packages.Any(…)) But what do you put in here?
  80. 80. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions "A lambda expression is an anonymous function that you can use to create delegates or expression tree types"
  81. 81. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions …huh? o_O
  82. 82. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions table => table.Name == "Product"
  83. 83. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions table => table.Name == "Product" The arrow is the lambda operator
  84. 84. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions table => table.Name == "Product" Input parameter is on the left side
  85. 85. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions table => table.Name == "Product" Expression is on the right side
  86. 86. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Lambda Expressions table => table.Name == "Product" For each object in collection, evaluate expression
  87. 87. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ and Lambda Chain LINQ Methods and use Lambda Expressions for simple and powerful querying of collections: .Where(table => table.Schema.Name == "Production") .OrderBy(table => table.Name)
  88. 88. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Filter collections Where() Returns the filtered collection with all elements that meet the criteria RootNode.Tables.Where(t => t.Schema.Name == "Production") OfType() Returns the filtered collection with all elements of the specified type RootNode.Connections.OfType<AstExcelOleDbConnectionNode>()
  89. 89. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Sort collections OrderBy() Returns the collection sorted by key… RootNode.Tables.OrderBy(t => t.Name) ThenBy() …then sorted by secondary key RootNode.Tables.OrderBy(t => t.Schema.Name) .ThenBy(t => t.Name)
  90. 90. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Sort collections OrderByDescending() Returns the collection sorted by key… RootNode.Tables.OrderByDescending(t => t.Name) ThenByDescending() …then sorted by secondary key RootNode.Tables.OrderBy(t => t.Schema.Name) .ThenByDescending(t => t.Name)
  91. 91. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Sort collections Reverse() Returns the collection sorted in reverse order RootNode.Tables.Reverse()
  92. 92. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Group collections GroupBy() Returns a collection of key-value pairs where each value is a new collection RootNode.Tables.GroupBy(t => t.Schema.Name)
  93. 93. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Aggregate collections Count() Returns the number of elements in the collection RootNode.Tables.Count() RootNode.Tables.Count(t => t.Schema.Name == "Production")
  94. 94. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Aggregate collections Sum() Returns the sum of the (numeric) values in the collection RootNode.Tables.Sum(t => t.Columns.Count) Average() Returns the average value of the (numeric) values in the collection RootNode.Tables.Average(t => t.Columns.Count)
  95. 95. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Aggregate collections Min() Returns the minimum value of the (numeric) values in the collection RootNode.Tables.Min(t => t.Columns.Count) Max() Returns the maximum value of the (numeric) values in the collection RootNode.Tables.Max(t => t.Columns.Count)
  96. 96. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Check collections All() Returns true if all elements in the collection meet the criteria RootNode.Databases.All(d => d.Name.StartsWith("A")) Any() Returns true if any element in the collection meets the criteria RootNode.Databases.Any(d => d.Name.Contains("DW"))
  97. 97. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Check collections Contains() Returns true if collection contains element RootNode.Databases.Contains(AdventureWorks2014)
  98. 98. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Get elements First() Returns the first element in the collection (that meets the criteria) RootNode.Tables.First() RootNode.Tables.First(t => t.Schema.Name == "Production") FirstOrDefault() Returns the first element in the collection or default value (that meets the criteria) RootNode.Tables.FirstOrDefault() RootNode.Tables.FirstOrDefault(t => t.Schema.Name == "Production")
  99. 99. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Get elements Last() Returns the last element in the collection (that meets the criteria) RootNode.Tables.Last() RootNode.Tables.Last(t => t.Schema.Name == "Production") LastOrDefault() Returns the last element in the collection or default value (that meets the criteria) RootNode.Tables.LastOrDefault() RootNode.Tables.LastOrDefault(t => t.Schema.Name == "Production")
  100. 100. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Get elements ElementAt() Returns the element in the collection at the specified index RootNode.Tables.ElementAt(42) ElementAtOrDefault() Returns the element in the collection or default value at the specified index RootNode.Tables.ElementAtOrDefault(42)
  101. 101. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Project collections Select() Creates a new collection from one collection A list of table names: RootNode.Tables.Select(t => t.Name) A list of table and schema names: RootNode.Tables.Select(t => new {t.Name, t.Schema.Name})
  102. 102. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net LINQ: Project collections SelectMany() Creates a new collection from many collections and merges the collections A list of all columns from all tables: RootNode.Tables.SelectMany(t => t.Columns)
  103. 103. DEMO Practical Biml Coding
  104. 104. Classes and Methods
  105. 105. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net C# Classes and Methods BimlScript and LINQ not enough? Need to reuse C# code? Create your own classes and methods!
  106. 106. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net C# Classes and Methods public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  107. 107. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net C# Classes and Methods: Class public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  108. 108. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net C# Classes and Methods: Method public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  109. 109. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net C# Classes and Methods: Logic public static class Utilities { public static string GetName(AstTableNode table) { return table.Schema.Name.ToUpper() + "_" + table.Name.ToUpper(); } }
  110. 110. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Where do you put your C# code? Code Blocks <#+ ... #> Code Files <#@ code file="Utilities.cs" #>
  111. 111. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Code Blocks vs. Code Files Code Blocks • Used when logic is specific to one file • Reuse by including files with code blocks Code Files • Use code editor of choice • Create extension methods
  112. 112. Extension Methods
  113. 113. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Extension Methods "Make it look like the method belongs to an object instead of a helper class"
  114. 114. DEMO C# Classes and Methods
  115. 115. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net …the past 60 minutes… Practical Biml Coding C# Classes and Methods Code Management
  116. 116. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Feedback How can speakers and SQLBits improve? Community Where can you get involved and learn more?
  117. 117. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net Get things done Start small Start simple Start with ugly code Keep going Expand Improve Deliver often
  118. 118. Cathrine Wilhelmsen - contact@cathrinewilhelmsen.net @cathrinew cathrinew.net hi@cathrinew.net Biml resources and references: cathrinew.net/biml

Level Up Your Biml: Best Practices and Coding Techniques (Presented at SQLBits on February 24th 2018)

Views

Total views

4,308

On Slideshare

0

From embeds

0

Number of embeds

2,916

Actions

Downloads

23

Shares

0

Comments

0

Likes

0

×