Code Generation Templates for Transport Objects Based on a Domain Model

In many application scenarios it is necessary to use transport objects based on the persistent objects from the data access layer. In order to take advantage of such objects, they first have to be written. Additionally, code that translates transport to persistent objects and vice versa is needed. When a big persistent model is used writing all this code could be a considerable effort.

Since the new code generation mechanism of OpenAccess is very powerful,
this process can be automated. The aim of this article is to provide
code generation templates which would dramatically decrease the time for
implementing data transfer objects (DTO). It is important to know that
the provided T4 templates can be used only with an OpenAccess domain
model.

The DTOs could be generated automatically if you use the Generate OpenAccess Domain Model Service wizard. However two things should be pointed out about the wizard. First, it is still a Beta version. Second, except the DTOs, it will generate a WCF service.

SOLUTION

1. Download and extract the attached templates (links are provided at the end of the article).

2. You should see a file named Telerik.OpenAccess.DTO.tt.

3. Copy and include this file in the Visual Studio project that contains your domain model.

4. Open the Telerik.OpenAccess.DTO.tt file and on the third line change the name of the .rlinq file so that it matches the name of the file containing your domain model. By default, the template will look for a file named EntityDiagrams1.rlinq.

5. Depending on the Visual Studio version used, line 19 and lines 24 to 28 have to be updated, so that the correct include files and Telerik.OpenAccess.CodeGeneration assembly are used. If needed, change the assembly path to {OpenAccess install path}\dsl2008\Telerik.OpenAccess.CodeGeneration.dll for Visual Studio 2008, or {OpenAccess install path}\dsl2010\Telerik.OpenAccess.CodeGeneration.dll for Visual Studio 2010. The paths of the include files should be updated in the same manner.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.