In July Microsoft released a preview of its upcoming Silverlight 3 RIA Services Framework which comes along with a new data source control – DomainDataSource. The DomainDataSource introduces a new way of accessing data by giving us a nice separation from the particular representation of our Data Model and more control over how the data is being retrieved or manipulated.
This post will provide you with a quick walk-through on how to use the DomainDataSource with our RadGrid control.
As mentioned above the DomainDataSource control is part of the MS .NET RIA Services Framework, so you need to first download and install the latter. Before proceeding to the installation of the RIA Services, however, you should make sure that Microsoft Silverlight 3 Tools for Visual Studio 2008 SP1 are installed on your machine. After having completed all installation requirements, we are now ready to go on to our sample web application.
Open Visual Studio 2008, create a new ASP.NET Web Application and add a Data Model to it – I have chosen to work with LINQ TO SQL against the Northwind database:
Before continuing to the next step you need to build the project so that the data classes and data context be generated and available to be exposed to the Domain Service.
Add a new item to the web application and select the Domain Service template under the Web category:
From the domain service dialogue select the NorthwindDataContext and choose the Customer entity as well as any other entities for which you may want Visual Studio to generate code that exposes the data:
The data access code that consists of CRUD methods to work with the data context is contained in the NorthwindDomainService.cs and with LINQ TO SQL looks as follows:
public class NorthwindDomainService : LinqToSqlDomainService<NorthwindDataContext>
public IQueryable<Customer> GetCustomers()
public void InsertCustomer(Customer customer)
public void UpdateCustomer(Customer currentCustomer)
public void DeleteCustomer(Customer customer)
Make sure that your application has a reference to the Microsoft.Web.Extensions and System.Web.DomainServices.WebControls assemblies.
Open the default.aspx web form and include the following register directive to the page:
<%@ Register TagPrefix="asp" Namespace="System.Web.DomainServices.WebControls"
Add the following mark-up for the DomainDataSourceControl:
Note that the DomainDataSource should specify the full namespace name for its DomainServiceTypeName property as well as the method that should be used to retrieve the data.
And last but not least, declare the RadGrid control:
And this is all that is needed to have RadGrid bound to a DomainDataSource control and automatically perform CRUD operations against its underlying data repository.
Download sample code (WCF RIA Services for Silverlight 3.0 & Visual Studio 2008): RadGridAndDomainDataSource
Download sample code (WCF RIA Services for Silverlight 4.0 & Visual Studio 2010): HierarchicalRadGridWithDomainDataSource
Iana Tsolova is Product Manager at Telerik’s DevTools division. She joined the company back in the beginning of 2008 as a Support Officer and has since occupied various positions at Telerik, including Senior Support Officer, Team Lead at one of the ASP.NET AJAX teams and Technical Support Director. Iana’s main interests are web development, reading articles related to geography, wild nature and latest renewable energy technologies.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.