The topics in this section demonstrate how to specify various additional code generation options, such as code generation templates, mapping type and output folder for the generated objects.
Code Generation Options
The Code Generation Options could be specified during the domain model generation, in the Advanced Options Dialog. Once your model is generated, you are still able to change the code generation options. In order to do so, you need to go to the Code Generation Settings tab page in the Model Settings Dialog.
- Code Generation Template - 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. For example, OpenAccess ORM uses T4 templates to generate your domain classes. In the Customizing Code Generation section, you will learn how to customize the code generation templates used by the Visual Designer.
- Mapping Type - Telerik OpenAccess ORM maps a database to a domain model by either applying attributes or by using an external XML mapping file. When you use the Attributes Mapping Type, the mapping information is exposed as CLR attributes applied to the domain classes and their properties. A domain class is just like any normal object class that you might define as part of your application, except that it is annotated with special information that associates it with a particular database table. These annotations are made as custom attributes on your class declaration. In case of a XML Mapping Type, the mapping information is preserved in the form of a Xml file.
||There is a third mapping type - Fluent Mapping. However, it can be enabled from a different place. For more information, see the Fluent Mapping Code Generation section below.|
- Generate Context - the Generate Context option specifies if the OpenAccessContext will be generated for the domain model or not. This option is useful when you want to separate your domain classes and the context in different assemblies. For more information, please read How to: Define an OpenAccessContext in a Separate Assembly.
- Generate Multiple Files - if the Generate Multiple Files option is checked, then different file for each object from the domain model will be generated. If you uncheck this option, then all classes will be defined in a single file.
- Project Folder/File Folder - a destination folder in the solution could be optionally chosen. If a folder is specified, then all objects will be generated in that folder. Those settings are enabled only if the Generate Multiple Files option is set to True.
- Generate in Nested Namespace - when this option is checked, the Code Generation Engine will respect the class namespaces and generate the classes in the corresponding folders (which will be automatically created by the code generation engine). That setting is enabled only if the Generate Multiple Files option is set to True. For more information, check out How to: Generate Classes in Different Namespaces.
Fluent Mapping Code Generation
The Fluent Mapping Code Generation functionality allows you to mix the Code Only with Database First and Model First approaches. It allows you to generate most of the necessary code automatically as it is done with the Visual Designer domain models. At the same time, since the generated code contains Fluent Mapping API, you can benefit from the capabilities this API offers you for modifying and extending the domain model.
The XML and Attributes mapping types can be enabled from the Advanced Options Dialog or from the Model Settings Dialog. However, the Fluent Mapping code generation can be enabled from a different place. OpenAccess ORM provides two templates for Fluent Mapping code generation.
The Telerik OpenAccess Fluent Library project template will add a new project to the solution and it will run the Create New Model Wizard. This template works in the same way as the Telerik OpenAccess Class Library project template. However, it will create a new model (from an existing database or an empty one) by using the fluent mapping code generation.
Basically, the Telerik OpenAccess Fluent Model item template will add a new fluent model to an existing project. This template works in the same way as the Telerik OpenAccess Domain Model item template. It will run the Create New Model Wizard and it will create a new model from an existing database or an empty one. However the used code generation will be Fluent Mapping.
The third possible way is to use the Model Settings Dialog in an existing .RLINQ file. For more information see the Fluent Mapping.