ECMA-CLI(Mono)/.Net CLR Runtime Hosting tutorial
Integrating Common Language Runtime Objects with Virtuoso Using C# Objects to extend Virtuoso via User Defined Types.

## Overview

The following tutorial demonstrates how Virtuoso can be extended through the use of a .NET bound language such as C# to create User Defined Types (UDTs), Stored Procedures, and Functions. This is an enhancement of its Object-Relational Database functionality.

The demonstrations in this section highlight transparent integration (hosting) between Virtuoso and the Microsoft .NET and Mono implementations of the ECMA Common Language Infrastructure (CLI).

## Prerequisites

The following prerequisites ensure the usability of these tutorial demos on Windows or Linux (and in other future Mono implementations):

- Linux
  - Mono Runtime and Frameworks (ideally the version bundled with Virtuoso)
  - Mono SDK (if you seek to write your own Objects for integration with Virtuoso)
  - Virtuoso Universal Server for Linux with Mono Hosting
- Windows
  - .NET Runtime and Frameworks
  - .Net Runtime and Framework SDK (if you seek to write your own Objects for integration with Virtuoso)
  - Virtuoso Universal Server for Windows with .NET CLR Hosting

## Tutorial Example

The following tutorial shows how C# classes are used to create User Defined Types (UDTs) in Virtuoso.

Please follow the steps below to maximize the value of this tutorial:

1. Click on the "Set Initial State" link which registers the two C# classes with Virtuoso. Click on the "ho_s_2.sql" link to see the code behind this step
2. Click on the "Run" links to actually experience the demo

Demo Breakdown

1. "ho_s_2.sql" performs the following steps
   1. Registers the "MyFinances" and "Point" classes with Virtuoso. Click on the "MyFinances.cs" and "Point.cs" links to see the C# source code of these classes
   2. Creates the conventional SQL table "Employee"
   3. Creates the Object-Relational table "Supplier" that includes a column named "Location" that is of Type "Point" (a UDT)
   4. Populates each of the newly created tables with data
   5. Creates the "distance" stored procedure which uses a C# function member (method) to calculate the distance between points.
2. "vsp1.vsp" uses the static method "tax" of the "MyFinances" class to compute the payroll tax values for each employee via the "salary" column (like a SQL function would). Take note of the Virtuoso class invocation syntax for static C# methods (the relevant member function type in this demo; true to C# these are called by name rather than instance).
3. "vsp2.vsp" uses the "distance" method of the UDT based column "location" to test for distance values less than "3". The distance values are return values from the "Point" class. Note that the "Point" class computes the distance between two arbitrary points.
4. "vsp3.vsp" is a variation of the previous demo, with the column "location" being used to access and conditionally test the values of data member "x" (shown in "Point.cs" as 0).
5. "vsp4.vsp" is another variation of a query on the "Supplier" table, in this particular case the query uses a Stored Procedure (see definition in "ho_s_2.sql") to filter its result set. It achieves this by using data member values "x" and "y" from column "location", and the arbitrary values 1 & 2 as input parameters for the Stored Procedure "distance". It then tests the return values for those less than 3.