ADO.NET Data Services Advanced Topics - Custom proxy based on T4 templates

1. Introduction

This is the first article of my series about deep dive into  ADO.NET Data Services. In this article I’m going to show you how to implement your own ADO.NET Data Services proxy with T4 templates.

Source code and database backup

2. Content

2.1 Problem

ADO.NET Data  Services is a very powerful toy, but as many other cool Microsoft technologies it needs some workarounds to become usable in the real world applications.

Most of the problems are connected with the auto generated proxy which is created after the addition of a service reference. Here are the most popular:

1. Data Contract objects do not support INotifyPropertyChanged which is needed for two way data binding.There are partial methods for detecting changes to specific properties which makes implementing the INotifyPropertyChanged interface possible, but not quick.

2. Add some common interface for all generated entites. (e.g. IIdentifyable)

3. Add custom attributes to properties of generated entities.

4. And many many others, which is caused by absence of control over the code generation process.

Uncontrolled code generation is a problem of all Microsoft ORM products, that is why community have created similar projects for LINQ to SQL (Damien Guard) and Entity Framework (Danny Simmons, ADO.NET team).

2.2 Solution

Solution to this problem is using of T4 templates for generation of ADO.NET data service proxy. In this case you will have absolute control over code generation process, so such task as implementing INotifyPropertyChanged interface will become trivial.

Mostly I was inspired by Damien Guard project T4 template for generating LINQ to SQL Data Context. It was my first experience with T4 templates, that’s why template helpers code may be a bit dirty.

2.3 How it works   see more

Similar posts

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment