Common Code Generation Functionality

Entity Developer code generation lets you use templates to generate source code for ORM models. Entity Developer has a very flexible code generation system, based on templates, written in T4-like Template Language.

It is much more convenient to use our templates in the model than usual T4 templates, because Entity Developer manages the process of code re-generation (when text templates are used, code is re-generated only when the template is saved or a specific button is clicked). In other words, if a changed model is saved, its code is automatically regenerated. Note, that Entity Developer supports integration with Visual Studio refactoring that enables renaming of model objects. For example, when renaming an entity, refactoring will ensure that any references to that class are renamed across your solution. Refactoring is performed when you save your project and is applicable to namespaces, classes and complex types as well as their properties, enums and their members; for LinqConnect and Entity Framework models it also applies to the context class and its properties.

Entity Developer models can have a freely defined set of templates. This allows generating non-connected code against different templates. The advantage of using Entity Developer is that Entity Developer manages all actions related to code generation. That is, all the templates are re-generated when the model is changed. The Model Explorer window provides a convenient means for managing templates.

When developing a model that at certain moments can become invalid, you may disable template generation by using the Enabled property of a model template.

 

ExpandedToggleIcon        Storing Templates

Templates can be stored both within the model and in Entity Developer resources.

The advantages of the first approach are the following:

the template is stored in the model and can be stored in a source control system;
the template can be moved to other computers or into different folders;
the template is editable.

The advantage of the second approach is the following:

If you need to frequently update versions of Entity Developer, you can always be sure that your template remains actual.
It is possible to add templates to the model both at the creation stage and at any other moment using a handy editor functionality.
the template is editable.

To add a template stored on the disk to the model, you should use the Add Existing command in the editor.

 

ExpandedToggleIcon        Predefined Templates

The Entity Developer application contains the following predefined templates:

Entity Framework:
oEntityObject – generates a strongly-typed ObjectContext class and persistence-aware classes;
oPOCO Entity – generates a strongly-typed ObjectContext class and classes with persistence ignorance;
oSelf-Tracking Entity – generates a strongly-typed ObjectContext class and self-tracking entity classes;
oDbContext – generates a strongly-typed DbContext class, persistence ignorant entity classes, and fluent mapping code for them;
oRepository and Unit of Work – generates Repositories and Unit of Work classes;
oData Annotations Metadata – generates Data Annotations metadata classes and decorate entity classes and properties with Data Annotations attributes that specify validation rules, data display settings, and define metadata for Windows Communication Foundation, Dynamic data, and WCF RIA Services;
oData Transfer Objects – generates Data Transfer Object (DTO) classes;
oWCF RIA Domain Service – generates a WCF RIA Services domain service class;
oMVC Controller – generates a ASP.NET MVC controller with data access code;
oMVC View Advanced – generates an ASP.NET MVC view based on Twitter Bootstrap.
Entity Framework Core:
oEF Core – generates classes for entities, enumerated types for enums, and it also generates fluent mapping for them;
oRepository and Unit of Work - generates Repositories and Unit of Work classes;
oData Annotations Metadata - generates Data Annotations metadata classes and decorating entity classes and properties with data annotation attributes;
oData Transfer Objects - generates Data Transfer Object (DTO) classes.
oMVC Controller - generates a ASP.NET MVC controller with data access code;
oMVC View Advanced - generates a ASP.NET MVC view based on Twitter Bootstrap.
LINQ to SQL:
oLINQ to SQL – generates a strongly-typed DataContext class and persistence-aware classes;
oPOCO Entities - generates a strongly-typed DataContext class and classes with persistence ignorance;
oLINQ to SQL for Windows Phone - generates a strongly-typed DataContext class and persistence-aware classes for Windows Phone applications;
oRepository and Unit of Work - generates Repositories and Unit of Work classes;
oData Annotations Metadata – generates Data Annotations metadata classes and decorate entity classes and properties with Data Annotations attributes that specify validation rules, data display settings, and define metadata for Windows Communication Foundation, Dynamic data, and WCF RIA Services;
oData Transfer Objects – generates Data Transfer Object (DTO) classes;
oWCF RIA Domain Service – generates a WCF RIA Services domain service class;
oMVC Controller - generates a ASP.NET MVC controller with data access code;
oMVC View Advanced - generates an ASP.NET MVC view based on Twitter Bootstrap.
NHibernate:
oNHibernate – generates NHibernate classes with XML mapping;
oFluent NHibernate – generates Fluent NHibernate Mapping classes;
oCastle ActiveRecord – generates Castle ActiveRecord classes;
oRepository and Unit of Work – generates Repositories and Unit of Work classes;
oData Annotations Metadata – generates Data Annotations metadata classes and decorate entity classes and properties with Data Annotations attributes that specify validation rules, data display settings, and define metadata for Windows Communication Foundation, Dynamic data, and WCF RIA Services;
oData Transfer Objects – generates Data Transfer Object (DTO) classes;
oMVC Controller – generates a ASP.NET MVC controller with data access code;
oMVC View Advanced – generates an ASP.NET MVC view based on Twitter Bootstrap.
Telerik Data Access:
oData Access – generates classes for entities and complex types, enumerated types for enums, and it also generates fluent mapping for them;
oRepository and Unit of Work - generates Repositories and Unit of Work classes;
oData Annotations Metadata - generates Data Annotations metadata classes and decorating entity classes and properties with data annotation attributes;
oData Transfer Objects - generates Data Transfer Object (DTO) classes.
oMVC Controller - generates a ASP.NET MVC controller with data access code;
oMVC View Advanced - generates a ASP.NET MVC view based on Twitter Bootstrap.

 

ExpandedToggleIcon        Template Properties

Code generation can be configured with the template properties, which are declared with the property directive in the templates.

Properties declared in this way are then displayed in the properties window and can be easily edited. In addition to standard properties of the property directive, Entity Developer supports the definition of a group and description.

 

ExpandedToggleIcon        Output Configuration

The standard T4 generator implements the IVsSingleFileGenerator interface and by default generates one file per template. Entity Developer extends this behavior using the Output class. Example: the entity-generating template generates one single cs file that is included into the .tt file project item, which is not very convenient in large projects.

All templates have the FilePerClass option as well as the EntitiesOutput and ContextOutput. EntitiesOutput and ContextOutput provide a capability that slightly differs in Visual Studio and in the stand-alone version, as described below.

If you are using Entity Developer as a Microsoft Visual Studio add-in, you can define the project and project folder to store generated code for contexts and entities of your model. In the Entity Developer stand-alone application, it is possible to define folders, in which generated code for entities and contexts is to be stored.

This set of options makes the development of multilayer applications easier and more convenient. For example, you can easily create the following structure of the application by setting the following options.

 

ExpandedToggleIcon        Custom Attributes Support

All templates support the generation of .NET attributes that are defined through a convenient dialog in the designer. In the designer, for example, you can define the System.ComponentModel.DataAnnotation attributes that will be generated in your classes.

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.