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