Getting started with LightSpeed 4 and RIA Services

As part of LightSpeed 4 we are now providing native support for exposing your LightSpeed entities via RIA services, by providing a custom DomainService implementation that works with LightSpeed entities.

Lets have a look at building a simple Silverlight application which uses LightSpeed and RIA Services to fetch its data. To get started, we will create a standard Silverlight application and enable RIA Services.


Next step is to set up our domain model, so I will create a standard LightSpeed model within the context of the Web solution and map out my entities – I am using the LightSpeed FilmFestival sample database as my model for the example. Because we will be shipping our objects over the wire, make sure you include references to System.ServiceModel and System.Runtime.Serialization so LightSpeed can generate up the appropriate DataContract mark-up on your entities.


The next step is to implement our custom DomainService, for this we have to write a simple class which extends a new part of the LightSpeed framework – the LightSpeedDomainService. This class lives in Mindscape.LightSpeed.ServiceModel.DomainServices which is a new assembly in 4.0.

Here is what an initial implementation looks like:

public class ModelDomainService : LightSpeedDomainService<ModelUnitOfWork>
  private ModelUnitOfWork _unitOfWork;
  protected override LightSpeedContext<ModelUnitOfWork> CreateDataContext()
    return new LightSpeedContext<ModelUnitOfWork>("Development");
  public ModelUnitOfWork UnitOfWork
      if (_unitOfWork == null)
        _unitOfWork = CreateTypedUnitOfWork();
      return _unitOfWork;

We now need to extend it by adding a [AllowClientAccess] attribute and exposing the appropriate entity types which we wish to allow access to over the wire.

If I am exposing the Film entity I would write the following:

public IQueryable<Film> GetFilms()
    return UnitOfWork.Films;
public void InsertFilms(Film film)
public void UpdateFilms(Film film)
public void DeleteFilms(Film film)

You will note that we use our access to the strongly typed UnitOfWork as a property and we can use the IQueryable properties to scope what is returned via Get() accordingly. For the Insert/Update/Delete methods we just need to provide stubs so RIA Services understands that these are available, the actual implementation handling these is already provided in the base class.

Compile it up and we will now have a DomainDataSource available to us in the Silverlight client application.


And now we can simply use the available data to do something cool – like show a CoverFlow of all of the Films we have screening currently!


If you are keen to try this at home, grab the code for this example and try this out with LightSpeed 4 and Silverlight Elements 2.

We’d love to hear from you!

To help make this the best release of LightSpeed ever we would love to hear your feedback on LightSpeed 4 Beta. Fire us an email, post in the forum, poke us on twitter – whatever way you want, we want to hear your feedback. Bug reports, feature suggestions – anything.

Download it now!

Current LightSpeed customers can download immediately from their account page. Look for “LightSpeed 4 Beta Program”. The nightly builds will be available under the files for this product. If you’re not yet a customer, go and check out the free version of LightSpeed 3.11 and see what you’re missing out on! :-)

Notes for the beta

If you’re using the beta, please remember:

  • Uninstall any existing installations of LightSpeed before installing the Beta.
  • LightSpeed 4 does not install side by side with LightSpeed 3.

3 Responses to “Getting started with LightSpeed 4 and RIA Services”

  • Am I being daft? I am getting the following error when trying to run the sample. I don’t seem to be able to get the sample working.

    “The type or namespace name ‘Web’ does not exist in the namespace ‘RIAServicesExample’ (are you missing an assembly reference?)”

  • Hi Jeremy,
    I’m not sure if I’m doing something wrong but I followed your example exactly but I’m not getting the same results. Also the [AllowClientAccess] does not exist I had to use the [EnableClientAccess] attribute.

    I’ve used the sample and it’s also not working.

    Kind regards,

  • Make sure you add the [Query] attribute to the IQueryable methods, since SP1 this seems to be required to cause the RIA Services entity generation to fire.


  • Leave a Reply


Join our mailer

You should join our newsletter! Sent monthly:

Back to Top