With the Q1 release of Telerik OpenAccess ORM, Telerik released a brand new LINQ Implementation and supporting Visual Entity Designer. With the upcoming Q2 release next month, we will introduce full WCF RIA Services support. If you want to get started now you can wire up the services yourself pretty easily. Let’s take a look at how to get your feet wet with RIA Services and Telerik’s LINQ implementation.
Before you get started, you will need a few things installed:
Getting Started: The Easy Stuff
Let’s create a new Silverlight application first. In the New Silverlight Application dialog, check the “Enable WCF RIA Services” checkbox. This will enable RIA Services.
The next step is to create a new Telerik Domain Model in the server (ASP.NET) project. I have a detailed walk through here on how to do that. We’ll create a new Domain Model by right clicking on the server project and selecting “Add” and choosing the Telerik Domain Model from the menu. Then we will map all of the tables from Northwind using the wizard. We’ll also keep the default model name of NorthwindEntityDiagrams.
We’re in good shape. So far if you have used the new LINQ Implementation nothing is new (or LINQ to SQL/EF for that matter.) Now let’s add the RIA Services stuff.
Since our RIA Services support is still beta, you have to wire up a few things manually, including some references. You need to add:
Now we are ready to create the domain class.
Creating the Domain Class
Add a new Domain Service Class by right clicking and selecting Add|New Item and choose Domain Service Class.
Accept the defaults in the dialog and then we are ready to go. (Note at this time OpenAccess does not support creation of the class for metadata, but will soon, possibly even before Q2.)
Once you accept this dialog, a new empty class is generated.
2: public class DomainService1 : DomainService
We need to add a using statement so we can make sure our DomainService uses the OpenAccess model: using Telerik.OpenAccess;
Now change the inheritance of DomainService1 to this:
2: public class DomainService1 : OpenAccessDomainService<NorthwindEntityDiagrams>
Now we have one last step to create our DomainService, we have to add the CRUD methods. (In the future all of this will be done automatically for you!)
2: public IQueryable<Customer> GetCustomers()
4: return this.DataContext.Customers;
7: public void InsertCustomer(Customer c)
12: public void DeleteCustomer(Customer c)
These are the methods of your DomainService. You can also add business logic here. Let’s do that with our GetCustomers() query. I will write some business logic that filters all of the customers by the country of Germany. Of course you would have more complex business logic here, however, I just want to demonstrate the point. All clients that use this DomainService will inherit this business logic, even if you expose your service as an OData feed. Our implementation is here:
1: public IQueryable<Customer> GetCustomers()
3: return this.DataContext.Customers
4: .Where(c=> c.Country=="Germany")
5: .OrderBy(c=> c.CustomerID);
Now you are done. Compile and let’s get cracking on a Silverlight client.
Creating the Silverlight Client
This is the easy part. We’ll use the RIA Services drag and drop features. Open MainPage.XAML in the Silverlight application and in the Data Sources window, drag and drop the Customer entity to the XAML form. (Tip: if the Data Sources window is blank or not showing up, you can manually force it to come up via the “Data” menu option on the main menu in Visual Studio.)
Once you drag and drop the entity to the form, a grid will automatically show up.
Now press F5 and see the application running.
That's it! We just created an OpenAccess based RIA Services application!
Of course there is a lot more to RIA Services than just binding a grid, however, this demonstration should show you that once you create your DomainService class, all of the RIA Services “stuff” just works for you. In future posts we will look at more RIA Services features as well as creating a query method.
Page rendered at Wednesday, 26 July 2017 14:48:55 (Eastern Daylight Time, UTC-04:00)
The opinions expressed herein are my own personal opinions and do not represent
my employer's view in anyway.