Data Transfer Objects Template

This template is designed for generating a Data Transfer Object (DTO) classes. This template is available both in C# and Visual Basic.

Template Description

This template can generate both DTO classes and converter classes with extension methods for converting entities to DTO and vice versa. These converter classes are partial classes with partial methods that you can use to customize the conversion process. If generated converter classes are not suitable for you, you can disable their generation with the Generate Converters property and use some third-party library, for example, AutoMapper, to convert objects.

When converting domain classes to DTO, you can convert either a single object or the object itself and all the objects, related to it. The following methods are available:

ToDto
ToDtos
ToDtoWithRelated
ToDtosWithRelated

When converting domain classes to DTO, you cannot convert related objects automatically. The following methods are available:

ToEntity

ToEntities

note Note

All the NHibernate collections must be generic if you want to generate converters. To create a model with only generic collections, make sure the Default Collection Generic check box on the Model Properties page of Create Model Wizard is selected (it is selected by default). Otherwise, if your model contain non-generic collections, set the Generate Converters template property to False.

Template Properties

DTO Classes

DTO Class Name Prefix

If this property is set, when generating a DTO class name, the value of this property is added to the name as a prefix.

DTO Class Name Suffix

If this property is set, when generating a DTO class name, the value of this property is added to the name as a suffix. Default value is 'Dto'.

DTO Classes In Associations

If it is set to True, navigation properties for DTO classes are generated on any association end. These properties are generated as single DTO Objects (for a (0..1) or (1) association end) or collections of DTO objects (for a (*) association end).

If it is set to False, the navigation properties for DTO classes are generated only for (*) association ends.

If the dependent class has a simple primary key that consists of a single property, the navigation property is a collection of primitive type elements (for example, List<Int32>), which are the primary key values of the dependent class. If the primary key of the dependent class consists of several properties, the navigation property is a collection of new DTO class objects (for example, List<OtherClassKeyDto>), that contain only the primary key properties of the dependent class. If the dependent class does not have a primary key, the navigation property is a collection of the existing DTO class (for example, List<OtherClassDto>).

DTO Constructors

If it is set to True, DTO class constructors are generated.

WCF Data Contract Attributes

If it is set to True, WCF Data Contract attributes will be generated.

DTO Conversion

Converter Class Name Prefix

If this property is set, when generating a DTO converter class name, the value of this property is added to the name as a prefix.

Converter Class Name Suffix

If this property is set, when generating a DTO converter class name, the value of this property is added to the name as a suffix. Default value is 'Converter'.

Generate Converters

If it is set to True, DTO converter classes will be generated. If there are non-generic collections in the model, this property must be set to False.

General

Description

Description of the template.

Enabled

Indicates whether the template is enabled. Acceptable values are True or False.

File Name

The name of the template file.

Name

The name of the template.

Type

The type of the template.

Generation

DTO Namespace

Specifies namespace for the generated DTO classes.

Header Timestamp Version Control Tag

If this option is set, the standard date/time-stamp in the file header will be replaced with the specified tag (e.g. a version control tag for Subversion, Git, etc.)

Output

Converters Output

Specifies output for the generated DTO converter classes.

Project

(This property is available in the Visual Studio add-in only) The name of the Visual Studio project where the generation result will be located.

Project Folder

(This property is available in the Visual Studio add-in only) The name of the directory in the Visual Studio project where the generation result will be located.

Destination Folder

(This property is available in the standalone application only) The directory to contain the generation results.

DTO Output

Specifies output for the generated DTO classes.

Project

(This property is available in the Visual Studio add-in only) The name of the Visual Studio project where the generation result will be located.

Project Folder

(This property is available in the Visual Studio add-in only) The name of the directory in the Visual Studio project where the generation result will be located.

Destination Folder

(This property is available in the standalone application only) The directory to contain the generation results.

File Per Class

If it is set to True, each DTO class will be placed to the separate file when generating code, otherwise, all DTO classes will be placed into a single file.

Generate Partial Converters

If it is set to True, then, for each DTO converter class a partial class will be generated, in which the user can add code that is not overwritten by the designer.

Generate Partial DTOs

If it is set to True, then, for each DTO class a partial class will be generated, in which the user can add code that is not overwritten by the designer.

Validation

Validation Error Messages

Specifies error messages to associate with a validation control if validation fails. If you do not want to use hardcoded error messages (e.g. for the sake of internationalization), you can use error messages stored in the application resources. For this, specify the name of the resource type for error messages in the following format: ResourceType=<type name>. Additionally, the resource name for your error message for the corresponding validator must be equal to the name of a property from the ValidationErrorMessages property.

Email Message

Specifies the error message to associate with a validation control if email validation fails.

Expression Message

Specifies the error message to associate with a validation control if regular expression validation fails.

IPAddress Message

Specifies the error message to associate with a validation control if IPAddress validation fails.

Length Message

Specifies the error message to associate with a validation control if length validation fails.

Numeric Message

Specifies the error message to associate with a validation control if numeric validation fails.

Range Message

Specifies the error message to associate with a validation control if range validation fails.

Required Message

Specifies the error message to associate with a validation control if required validation fails.

Validation Framework

Defines the set of attribute types and its source to be used for validating the property values of generated classes. Acceptable values are EnterpriseLibrary, NHibernateValidator, DataAnnotations, None.

Extended Properties for Model Objects

Generate DTO

This property is available for all entity classes, properties, complex types, navigation properties, and associations. It determines whether to generate DTO class generation for this model objects. Default value is true, which means, the corresponding DTO object will be generated. If you want to disable generation of the corresponding DTO class, set this property to False.

 


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.