Telerik blogs

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.

Creating the Service

The first thing we need to do is add a new “WCF RIA Service Class Library” to our solution:

image 

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).

 image 

After we add the new projects, we need to add a reference to our model project:

image 

Now we can add a “Telerik OpenAccess Domain Service” to the RIA service web project:

image

Select our DataContext from the drop down, and enable all entities, and also go ahead and enable editing:

image

Set up the Service

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 )

void GeneratePerEntityDomainServiceCRUDOperations(string className, string classType)
{

In this method you will see the following code:

public IQueryable<<#=classType#>> Get<#=className#>()
{
return this.DataContext.<#=className#>;
}

We need to add:  [Query(IsDefault = true)] to this section, the resulting code looks like this:

[Query(IsDefault = true)]
public IQueryable<<#=classType#>> Get<#=className#>()
{
return this.DataContext.<#=className#>;
}

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:

[Query(IsDefault = true)]
public IQueryable<Client> GetClients()
{
return this.DataContext.Clients;
}

Now our service is ready to plug into LightSwitch!  In the next blog we will see how to get the service working in LightSwitch.

Part 1

Part 2

Part 3


Comments

Comments are disabled in preview mode.