Entities and Mapping Generation

This topic describes generation of entities and mapping in Entity Developer for NHibernate.

 

ExpandedToggleIcon        Available Templates

The following templates are included in Entity Developer for NHibernate:

NHibernate - this is the default entities and mapping generation template, available both in C# and Visual Basic.
Fluent NHibernate - this template is used as an addition to the NHibernate template and allows generating fluent mapping. This template is currently available only for C#.
Castle ActiveRecord - this template allows generating Castle ActiveRecord classes. This template is currently available only for C#.

 

ExpandedToggleIcon        Entities and Mapping Generation

The procedure below lists the steps required to generate entities in NHibernate.

To generate entities, perform the following sequence of actions:

1.In the Model Explorer window, under Templates, select NHibernate.

The properties of the selected template are displayed in the Properties window:

Images_TemplatePropertiesNHibernate

2.(Optional) To generate the Data Contract / Data Member attributes (used to serialize entities), in the Generation section of the Properties window, set the Generate Data Contracts parameter to True.
3.(Optional) To replace the standard date/time stamp in the file header with another tag (e.g. a version control tag for Subversion, Git, etc.), in the Generation section of the Properties window, set the Header Timestamp Version Control Tag parameter.
4.(Optional) To implement individual Equals and GetHashCode methods for each entity class, in the Generation section of the Properties window, set the Implement Equals parameter to True.
5.(Optional) To implement the IValidatable interface for each entity class, in the Generation section of the Properties window, set the Implement Validatable parameter to True.
6.(Optional) To implement the INotifyPropertyChanging and INotifyPropertyChanged interfaces for each model class, in the Generation section of the Properties window, set the Property Change Notifiers parameter to True.
7.(Optional) To generate the extensibility partial void On<property name>Changing and partial void On<property name>Changed methods, in the Generation section of the Properties window, set the Property Change Partial Methods property to True. These methods handle changes of each object property.
8.(Optional) To change the destination folder for generated entity classes, click the three-dotted button in the entry box of the Entities Output parameter and, in the displayed Browse for Folder dialog box, navigate to the required folder. Note that if no destination folder is specified, generated entities classes are stored to the folder, in which the model currently resides. See also the note below this procedure. The value of this property is taken into account during generation only if the File Per Class property is set to True.
9.(Optional) To have each model classes placed into a separate file at code generation, in the Output section of the Properties window, set the File Per Class parameter to True.
10. (Optional) To generate a partial class for each class in the model, in the Output section of the Properties window, set the Generate Partial Class parameter to True.
11. (Optional) Use the Validation Error Messages properties to specify error messages you want 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.
12. (Optional) To specify the validation framework for validating the property values of generated classes, in the Validation section of the Properties window, set the Validation Framework parameter.
13. (Optional) If no mapping generation is required, in the Xml Mapping section of the Properties window, set the Xml Mapping Action parameter to DoNotGenerateMappingFiles. Normally, this is not needed.
14. (Optional) To place mapping into a single file, change the default value (True) of the Xml Mapping File Per Class in the Xml Mapping section to False.
15. (Optional) To change the destination folder for generated mapping, click the three-dotted button in the entry box of the Xml Mapping Output parameter and, in the displayed Browse for Folder dialog box, navigate to the required folder. Note that if no destination folder is specified, generated mapping is stored to the folder, in which the model currently resides. See also the note below this procedure.
16. Save the model to generate entity and/or mapping files.

note Note

If you use Entity Developer as an add-in to Microsoft Visual Studio, in Steps 8 and 15 of the procedure above, you will be able to select the project to store generated entity and mapping files instead of the folder.

 

ExpandedToggleIcon        Fluent Mapping Generation

The capability of fluent mapping generation in Entity Developer for NHibernate is provided through the Fluent NHibernate template, included in Entity Developer.

To use fluent mapping, perform the following sequence of actions:

1.(Optional) If the Fluent NHibernate template is not present in the Model Explorer window, add it to the model. For more information on how to add templates to the model, refer to the Basic Operations With Templates section.
2.(Optional) To replace the standard date/time stamp in the file header with another tag (e.g. a version control tag for Subversion, Git, etc.), in the Generation section of the Properties window, set the Header Timestamp Version Control Tag parameter.
3.(Optional) To place all mapping into a single file, change the default value (True) of the File Per Class parameter in the Output section to False.
4.(Optional) To change the destination folder for generated mapping, click the three-dotted button in the entry box of the Output parameter and, in the displayed Browse for Folder dialog box, navigate to the required folder. Note that if no destination folder is specified, generated mapping is stored to the folder, in which the model currently resides. See also the note above.
5.Save the model to generate entity and/or mapping files.

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.