In the last blog we looked at creating an OpenAccess domain model to expose to LightSwitch. In this blog we continue down the path of integrating OpenAccess and LightSwitch. Today we will set up an OpenAccess Domain Service that can be consumed by LightSwitch.
The first thing we need to do is add a new “WCF RIA Service Class Library” to our solution:
This will add a new folder to our solution containing 2 projects, one is the RIA Service library(Demo.OALightSwitch.Web), and the other is a Silverlight client project(which we can ignore for these blogs).
After we add the new projects, we need to add a reference to our model project:
Now we can add a “Telerik OpenAccess Domain Service” to the RIA service web project:
Select our DataContext from the drop down, and enable all entities, and also go ahead and enable editing:
In order to use RIA services with LightSwitch, each entity query we want to expose needs to have a default query specified. We could go directly edit the code OpenAccess generates, but that is generally not a good idea. Moreover, if we have a large model this could be painful! Instead open the DomainService.tt. This is the T4 template OpenAcess uses to generate the OA Domain Service.
Scroll down to the “GeneratePerEntityDomainServiceCRUDOperations” method: ( should be ~line 80 )
In this method you will see the following code:
We need to add: [Query(IsDefault = true)] to this section, the resulting code looks like this:
Now save the template file, and open up the generated code file. You should see standard CRUD operations for each entity, and the Get’s should have the new attribute applied like so:
Now our service is ready to plug into LightSwitch! In the next blog we will see how to get the service working in LightSwitch.
Subscribe to be the first to get our expert-written articles and tutorials for developers!