Data Access has been discontinued. Please refer to this page for more information.

How to: Extend Data Service

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

This topic illustrates how to extend the generated WCF Data Service on the server. When working with automatically generated source (like the data service class generated by the Service Wizard), code can be added to the class without having to modify the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code and so on. You can create code that uses these classes without having to edit the file created by Visual Studio. Using partial classes is a perfect solution for separating auto-generated code from developer code. The most compelling reason for using partial class is to separate your application business logic from the designer-generated code.

You may ask yourself "Why do I need to use partial classes?". You could try the following experiment. Modify the data service class by adding a new dummy method to the class definition. After that, re-generate your WCF Data Service with the wizard. Now take a look at the class again. The method you just added is gone and the original definition of the class has been restored.

Do not modify the original source file of a data service class. Each time you re-generate your service, all changes will be lost. Instead, add your custom methods in a partial class.

Basically, what you need to do is:

  1. Create a new class with the same name as the name of the domain service you want to extend.
  2. The new partial class should be in the same namespace as the original.
  3. Mark the class with the partial keyword.
  4. Add your custom methods, e.g. Interceptors.

To see the EntitiesModelService.svc.vb file in VB projects, use the Show All Files command from the Solution Explorer toolbar.

public partial class EntitiesModelService
   [QueryInterceptor( "Cars" )]
   public Expression<Func<Car, bool>> OnQueryCars()
       return o => o.CarYear == 2001;
Partial Public Class EntitiesModelService
    Public Function OnQueryCars() As Expression(Of Func(Of Car, Boolean))
        Return Function(o) o.CarYear = 2001
    End Function
End Class