.NET RIA Services is a new framework from Microsoft that simplifies the development of n-tier web applications. A typical application will consist of a presentation layer, application logic and a data access layer. In these examples a combination of Silverlight 3 and .NET RIA Services will provide the presentation layer and application layer while the data will reside in Virtuoso and be accessed using the Virtuoso ADO.NET provider. The first example demonstrates how to display data from the Employee table in the Demo database in a grid on a web page. The second example shows how to display IRIs from the Linked Data Views of the demo data. The IRIs are used to create hyperlinks that are the starting point for exploring the linked data.
Step 1 - Create the Visual Studio Projects.
![]() |
Figure: 2.14.2.1. .NET RIA Services Application |
At this point a skeleton solution is created that consists of a client project called DemoApplication and a server project called DemoApplication.Web. This application will use data from the Virtuoso database. We add the data and its schema to the application by adding an ADO.NET entity data model to the server project.
Step 2 - Add the Data Model
![]() |
Figure: 2.14.2.1. .NET RIA Services Application |
We want to make the entities in the model available to both the client and server parts of the solution. To do this we need to add a DomainService to the solution. However, to make the entities from the data model available to the domain service we must first build the solution.
Step 3 - Add a Domain Service.
![]() |
Figure: 2.14.2.2. .NET RIA Services Application |
This will create the DomainService class and generated code in both the client and server parts of the application. The Silverlight client can now interact with the data through the DomainContext class in the client project. At this point you need to build the solution again.
Step 4 - Display The Data
<data:DataGrid Name="EmployeeGrid"></data:DataGrid>
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using DemoApplication.Web; using System.Windows.Ria.Data; namespace DemoApplication { public partial class MainPage : UserControl { private EmployeeContext _employeeContext = new EmployeeContext(); public MainPage() { InitializeComponent(); LoadOperation<Employees> LoadOp = this._employeeContext.Load(this._employeeContext.GetEmployeesQuery()); this.EmployeeGrid.ItemsSource = LoadOp.Entities; } } }
![]() |
Figure: 2.14.2.3. .NET RIA Services Application |
One advantage of using Virtuoso as the data store is the seamless way in which we can use this use this application to display dereferencable IRIs and explore RDF linked data.
The Virtuoso SPASQL interface allows RDF data in the Virtuoso Quad store to be queried using SPARQL from any SQL interface by simply prefixing the SPARQL query with the keyword SPARQL. We will use the SPASQL interface to create a view containing the IRIs of the Employees in the the Demo RDF data in Virtuoso.
Step 1 - Create the View in Virtuoso
CREATE VIEW Demo.demo.sparqlview as SPARQL PREFIX nwind: <http://demo.openlinksw.com/schemas/northwind#> SELECT DISTINCT ?s FROM <http://demo.openlinksw.com/Northwind> WHERE { ?s a nwind:Employee }
Step 2 - Modify the Solution To use the View
![]() |
Figure: 2.14.3.1. .NET RIA Services Application |
![]() |
Figure: 2.14.3.1. .NET RIA Services Application |
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using DemoApplication.Web; using System.Windows.Ria.Data; namespace DemoApplication { public partial class MainPage : UserControl { private EmployeeContext _employeeContext = new EmployeeContext(); public MainPage() { InitializeComponent(); LoadOperation<sparqlview> LoadOp = this._employeeContext.Load(this._employeeContext.GetSparqlviewQuery()); this.EmployeeGrid.ItemsSource = LoadOp.Entities; } } }
![]() |
Figure: 2.14.3.1. .NET RIA Services Application |
To realize the power of linked data we would now liked to begin exploring this data by clicking on these IRIs.
Step 3 - Make Hyperlinks From IRIs
<UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="DemoApplication.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> <Grid x:Name="LayoutRoot"> <data:DataGrid Name="EmployeeGrid" AutoGenerateColumns="False"> <data:DataGrid.Columns> <data:DataGridTemplateColumn Header="Employee"> <data:DataGridTemplateColumn.CellTemplate> <DataTemplate> <StackPanel x:Name="DisplayEmployeeData" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="5" > <HyperlinkButton Content ="{Binding s}" NavigateUri="{Binding s}" Margin="5,0,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="12"> </HyperlinkButton> </StackPanel> </DataTemplate> </data:DataGridTemplateColumn.CellTemplate> </data:DataGridTemplateColumn> </data:DataGrid.Columns> </data:DataGrid> </Grid> </UserControl>
![]() |
Figure: 2.14.3.1. .NET RIA Services Application |
![]() |
Figure: 2.14.3.1. .NET RIA Services Application |
![]() |
Figure: 2.14.3.2. .NET RIA Services Application |
The examples in this document show you how to simply display data in a browser using Silverlight 3 and .NET RIA Services. See an example of a more complicated application.
Previous
Creating a Silverlight Application to consume the service |
Chapter Contents |
Next
Creating a .Net RIA Services Application That Will Update Virtuoso Data |