Telerik OpenAccess ORM

Telerik OpenAccess ORM Send comments on this topic.
Overview
Programmer's Guide > Developer's Guide > Code Generation > Overview

Glossary Item Box

Code generation lets you use templates to generate part of your application's source code and other resources from a model. For example, your model could be a diagram that defines the flow of control through a series of user dialogs. Whenever you edit the model during development, the text templates generate part of the application code and configuration files from the diagram.

All examples in this section demonstrate how to customize the code generation templates used by the Visual Designer. To learn how to customize the templates for the Add OpenAccess Service Wizard, please refer to How to: Customize Code Generation.

The Visual Designer code generation templates reside in the Telerik OpenAccess ORM installation path - ~Telerik\OpenAccess ORM\dslXXX\CodeGenerationTemplates.

 

Where dslXXX is either dsl2008 or dsl2010. The dsl2008 folder contains the code generation templates used by Telerik OpenAccess ORM in Visual Studio 2008. Note, that if you don't have installed Visual Studio 2008 on your development machine, the dsl2008 folder won't be installed as well. Respectively, the dsl2010 folder contains the code generation templates for Visual Studio 2010.

All examples in this section are based on the code generation templates for Visual Studio 2010 (the dsl2010 folder).

The dsl2010\CodeGenerationTemplates folder contains the following sub-folders:

  • CSharp/VisualBasic - contain the C#/VB.NET code generation templates. When you generate a new Telerik OpenAccess Domain Model, the Create Model Wizard uses these templates.
  • DomainContext - contains the C#/VB.NET code generation templates used by the Telerik OpenAccess Domain Context item template. The OpenAccess Domain Context template is a Visual Studio template allowing you to create a new OpenAccessContext.
  • Dto - contains the C#/VB.NET templates for Data Transfer Objects generation.
  • DynamicData - contains the C#/VB.NET code generation templates used by the Telerik Dynamic Data Wizard.
  • FluentMapping - contains the C#/VB.NET code generation templates used by the Telerik OpenAccess Fluent Library project template. The Telerik OpenAccess Fluent Library project template is a Visual Studio template for creating an OpenAccess model using the FluentMapping API. For more information, take a look at Overview.
  • Ria - contains the C#/VB.NET code generation templates used by the WCF RIA wizard.

There are separate templates for CSharp and VisualBasic code. For example, navigate to the ~Telerik\OpenAccess ORM\dsl2010\CodeGenerationTemplates\CSharp folder. There is one template named DefaultTemplateCS.tt. This is the entry template. It simply contains the paths to the actual templates used by the designer

Go to the Includes folder. You should note the following code generation templates.

In the most cases, in order to customize the code generation, you should edit the General and/or Specific templates.

Changing the Code Generation Templates Used by the Visual Designer

To change the code generation templates used by the Visual Designer:

  1. Open the Model Settings dialog.
  2. Go to the Code Generation tab page.
  3. Check the "Custom Defined" option and go to the directory with the modified templates.
  4. You need to select the DefaultTemplateCS.tt file.

Best Practices for Customizing the Code Generation Templates

A recommended approach is to create a copy of the default templates and include it in your Visual Studio project. Thus, if you work in a team, every team member will be able to get the templates from the source control and use them. For example, if you are modifying the C# templates, then copy the entire ~Telerik\OpenAccess ORM\dsl2010\CodeGenerationTemplates\CSharp folder and include the copy in your Visual Studio project, check it in the source control and never change the default templates as they can be used as a backup.

Note that when you paste or save the templates, Visual Studio will automatically generate code files. Delete them.
By default Visual Studio doesn't offer syntax highlighting, syntax error reporting or intelli-sense when editing T4 templates. You can download T4 Editor, which fully integrate with Visual Studio from here.

 

In this section: