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

Customizing Code Generation - Overview

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.

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 Service Wizard, please refer to How to: Customize Code Generation.

General Information

The code generation templates of Telerik Data Access are updated and the newer versions can be used only in Visual Studio 2010 and Visual Studio 2012. Visual Studio 2008 uses their previous version. The articles in this section demonstrate the usage of the newer versions of the templates only.

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

Where dslXXX is either dsl2008, dsl2010 or dsl2012. The dsl2008 folder contains the code generation templates used by Telerik Data Access 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 and dsl2012 folder contains the code generation templates for Visual Studio 2010 and Visual Studio 2012.

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

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

There are separate templates for CSharp and VisualBasic code. For example, navigate to the ~Telerik\Telerik Data Access\dsl2012\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_ver.2 folder. You should note the following code generation templates.

  • Engine.ttinclude - contains the main control logic of the code generation. Determines when a domain context or/and FluentMetadataSource should be generated. Controls the file creation.
  • Template.ttinclude - initializes the rest of the generators as they are structured as classes. Deals with the dependency between them by injecting them via the constructors.
  • AttributesGenerator.ttinclude - generates attributes for all code elements that require them, such as classes, properties and method parameters.
  • ClassGenerator.ttinclude - generates all domain classes.
  • ContextGenerator.ttinclude - generates the domain context with all the constructors and endpoints.
  • DocumentationGenerator.ttinclude - generates all comments and XML documentation.
  • DomainMethodsGenerator.ttinclude - generates all domain methods for functions and stored procedures.
  • FluentMappingGenerator.ttinclude - generates the FluentMetadataSource.
  • InterfacesGenerator.ttinclude - generates the interfaces defined in the domain model and IXXXUnitOfWork.
  • NamespacesGenerator.ttinclude - generates the namespace blocks.
  • PropertiesGenerator.ttinclude - generates all properties in domain classes.
  • UsingsGenerator.ttinclude - generates the using statements in all files.

The entry template for fluent code generation is called FluentModel.tt. It is located in ~Telerik\Telerik Data Access\dsl2012\CodeGenerationTemplates\FluentMapping directory, in folders CSharp and VisualBasic for the respective languages.

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.

Code Generation Class Diagram

In order to produce what is required of them, the code generation templates rely on a hierarchy of CodeXxxx classes. Instances of those classes provide the matadata needed by the code generation templates in order to construct the unit of code suggested by the respective class name.

In this section: