In this short series of articles I’ll show you how to integrate Telerik OpenAccess ORM in Silverlight applications, how to solve issues when applying this pattern and how to take advantage from this great product. What will be covered?
In order to complete the walkthroughs, the following components should be installed:
Creating the RIA Service Solution
In the first part of the series, I’ll cover how to create a WCF RIA Service by using Telerik OpenAccess ORM and how to consume that service from a Silverlight Client application.
So open your Visual Studio and follow me. Create a new Silverlight project and name it, let’s say MyOpenAccessRiaDemo. Of course do not forget to check the Enable WCF RIA Services check box. By checking this check box, you will create a RIA Services link between the client project and the server project. Nothing unusual so far. Your solution should contain two projects: a client and a server project. The client project is named MyOpenAccessRiaDemo and it will contain the Silverlight code. The server project is named MyOpenAccessRiaDemo.Web and it will contain the middle-tier code.
Creating a Telerik OpenAccess Domain Model
The next step is to create a Telerik OpenAccess Domain Model that represents data from the Northwind sample database. RIA Services work with a variety of data modeling classes and data source. For example, you can use either Entity Framework or OpenAccess. If you are familiar with Entity Framework, then you should not have difficulties with the creation of Telerik OpenAccess Domain Model, but to make the data available in the middle tier.
Creating the Domain Service
The next several steps are extremely important. Why? The answer is that the creation of a Domain Service with Telerik OpenAccess ORM requires some additional work in comparison with the cases when you use Entity Framework on the server side. In this subsection, you will add a domain service to the middle-tier project. A domain service exposes the data entities and operations in the server project to the client project. You can add business logic to the domain service in order to manage how the client interacts with the data. To create a domain service:
// TODO: Create methods containing your application logic.
NorthwindDomainService : OpenAccessDomainService<NorthwindDbContext>
Creating the Silverlight Client Application
In this section, I’ll show you how to use the generated domain service and how to consume data. But first, let’s take a look at some of the characteristics of the project. Because a RIA Services link exists between the client project and the server project, client proxy classes are generated when you build the solution. These proxy classes enable you to access the data from the client. To see the generated client proxy class:
To display data in the Silverlight client:
MainPage : UserControl
NorthwindDomainContext domainContext =
LoadOperation<Customer> loadOperation =
domainContext.Load<Customer>( domainContext.GetCustomersQuery() );
.CustomersGrid.ItemsSource = loadOperation.Entities;
In the next article, I’ll show you how to add query methods in the Domain Service, how to perform Create, Update, and Delete operations, and how to validate data. Stay tuned for the next blog.