How to: Customize the Code Generation when Converting Forward Mapped Persistent Classes
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.
In this article you will see how you can apply customized code generation templates when converting Forward Mapped persistent classes.
When converting a Classic Model containing Forward Mapped Classes, a new Fluent Model will be generated. You can influence this generated model by applying customized code generation templates. The process of doing so includes the following steps:
- Preparation of the Project that Contains the Classic Model
- Preparation of the Code Generation Templates
- Customization of the Code Generation Templates
- Running the Classic Model Conversion Wizard
1. Preparation of the Project that Contains the Classic Model
- In the project housing your Classic Model, create a new folder named TelerikDataAccessCustomConversionTemplates.
- In this folder you will need to copy the FluentMappingCS.tt or FluentMappingVB.tt file depending on the used language. These files can be found in <install-dir>\dsl20XX\CodeGenerationTemplates\FluentMapping in the CSharp or VisualBasic folders respectively. Note that dsl20XX stands for the version of Visual Studio that you are using.
- In the TelerikDataAccessCustomConversionTemplates folder, create another new folder named Includes.
- In this folder you will need to copy the templates from <install-dir>\dsl2012\CodeGenerationTemplates\CSharp\Includes or <install-dir>\dsl2012\CodeGenerationTemplates\CSharp\Includes depending on the used language.
You will end up with a structure like the following:
The root folder for the customized templates must be named TelerikDataAccessCustomConversionTemplates otherwise the custom templates will not be discovered by the Classic Model Conversion Wizard.
2. Preparation of the Code Generation Templates
Once the templates are included in your project, you will notice that the Error List in Visual Studio will notify you of some errors. They occur because the templates delivered by Telerik Data Access require additional steps performed by the Classic Model Conversion Wizard. In order to avoid them you need to do the following:
- Delete the .cs or .vb file under each .tt file
- Delete the content of the Custom Tool property for every .tt file
3. Customization of the Code Generation Templates
At this point your templates are ready to be customized. Do note that the persistent classes of your Classic Model are not re-generated and will not be affected by changes in the templates.
4. Running the Classic Model Conversion Wizard
After you have customized your templates you can run the Classic Model Conversion Wizard to generate your customized Fluent Model.