Entity Property Validation

This topic deals with the validation mechanism implemented in Entity Developer.

The validation mechanism provides a possibility to check the validity of entity property values against constraints defined for that property through the attributes assigned to it.

In Entity Developer, the validation mechanism includes some of the properties available in the following validation frameworks:

Enterprise Library;
NHibernate Validator;
Data Annotations.

The procedures for enabling entity property validation, editing the validation template, saving a modified validation template and handling validation error messages are provided below.

 

ExpandedToggleIcon        Enabling Entity Property Validation

Before enabling the entity property validation mechanism, make sure that the validation parameters are correctly set for the properties of all the required entities in the model. If the Database-First approach has been used to create the model, some validation parameters can be set automatically.

To enable the entity property validation mechanism, perform the following sequence of actions:

1.In the Template node of the Model Explorer area, select the required template.
2.In the Validation section of the Properties area for the selected template, locate the Validation Framework row and select the appropriate framework.

The entity property validation mechanism is successfully enabled.

 

ExpandedToggleIcon        Validation Error Messages

In Entity Developer, you can specify error messages to be associated with a validation control for the cases when validation fails. If you do not wish to use hard-coded error messages (for example, for the reasons of internationalization), it is possible to use error messages stored in the application resources. For that purpose, you should specify the name of the resource type for error messages in the following format: ResourceType=<type name>.

Additionally, the resource name for an error message for the corresponding validator must equal the name of a property from the ValidationErrorMessages property.

The Validation Error Messages can be defined in the Validation Error Messages row in the Properties window for the corresponding template.

 

ExpandedToggleIcon        Editing and Saving Validation Templates

By default, when the entity property validation mechanism is enabled, the validation template is included into the template that is selected in Step 1 of the previous procedure.

If you need to edit the validation template, perform the following sequence of actions:

1.In the Template node of the Model Explorer area, right-click the template selected in Step 1 of the previous procedure and, from the drop-down menu, select Open.
2.In the code of the template, locate the following line: "include file="Validation.tmpl"".
3.Place the cursor on Validation.tmpl and press F12.
4.Copy the text of the validation template into a new file.
5.Make required change and save the file with the Validation.tmpl name into a location as described in the table below:

Usage Specifics

Where To Save

The validation template is used for a particular model generation template, which is not the same as the predefined template.

The validation template must be saved in the same folder as the model generation template.

The modified validation template is used for a particular model.

The validation template must be saved in the same folder as the model file. The name of the validation template file must be Validation.tmpl or MODELNAME.Validation.tmpl.

The modified validation template is used  in all models, for all ORMs, etc.

The validation template must be saved in the Shared Templates folder.

 


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.