T4 templates for WCF Data Services, Part -I

Click here to download sample application

As part of a series of blog posts about how to enhance the WCF Data Services development experience, I will be
releasing some of the T4 templates that I use for generating common code.
In this post, I will talk about augmenting the Server-side WCF Data Service by generating Query/Change Interceptors
for all given entity sets present in a model. As this is  proof of concept code only, this T4 template will only work against
and Entity Framework model and will generate C# code. It shouldn’t be too hard to change the template to generate VB code.

To use this template in your project, drop the three files in the zip file into the same project as the Data Service.

Specify the following parameters in the .tt file :

  string dataServiceClassName ="DataService";
  string dataServiceClassNamespace ="Ast4oriaT4Templates.Web";
  bool generateQueryInterceptors = true;
  bool generateChangeInterceptors = true;
  bool generateServiceOperations = true;
  string edmxFilePath =@"C:\temp\EuphoriaClientApp\EuphoriaWeb\northwindModel.edmx";

And save the template to trigger the code generation:

Once the code gen finishes, you should see the following files :

<dataServiceClassName>.QueryInterceptors.cs : This file contains a query interceptor for every entity set in the Model

<dataServiceClassName>.ChangeInterceptors.cs : This file contains a change interceptor for every entity set in the Model

<dataServiceClassName>.ServiceOperations.cs :  This file contains a service operation for every FunctionImport in the Model

Part II will be client side code generation of Service Operations in the generated proxies.

Comments

  • Anonymous
    September 10, 2010
    Thanks.  Looking forward to part 2.

  • Anonymous
    February 11, 2011
    Any chance of part two? Looking for client side code generation samples.