Data Transfer Objects Template

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

ExpandedToggleIcon        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

 

ExpandedToggleIcon        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. This property is obsolete and not recommended to use in new projects. Use the Serialization Library property instead.

WCF Data Member Attribute On Navigation Properties

Specifies when to generate the DataMember attribute for navigation properties. Applicable when WCF Data Contract Attributes is set to True. This property is obsolete and not recommended to use in new projects. Use the Serialize Navigation Properties property instead. The possible values are:

All

The attribute is always generated when WCF Data Contract Attributes is set to True. This is the default value.

OneEnd

The attribute is generated for navigation properties on the ends of associations that have cardinality one.

ManyEnd

The attribute is generated for navigation properties on the ends of associations that have cardinality many.

None

The attribute is never generated for navigation properties.

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.

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.

Serialization

Serialization Library

The library used for serialization. You can use one of the following libraries:

Data Contract - DataContractSerializer class is used.
JSON (Newtonsoft.Json) - Newtonsoft.Json library is used for serialization to JSON format.
JSON (Microsoft.Text.Json) - Microsoft.Text.Json library is used for serialization to JSON format.
YAML (YamlDotNet) - YamlDotNet library is used for serialization to YAML format.

Serialize Navigation Properties

Determines when serialization attributes are generated for navigation properties. Can be All, OneEnd, ManyEnd, or None.

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.

 

ExpandedToggleIcon        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.

Do Not Serialize

This property is available for all entity properties. Excludes properties from serialization.

 


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.