Code Generation

This topic deals with the generation of entities and mapping in Entity Developer for Entity Framework.

Currently Entity Developer provides only one EF Core template for generating Entity Framework Core entities and context. Entity Developer generates fluent mapping for Entity Framework Core.

 

ExpandedToggleIcon        Code Generation

The procedure below lists the steps required to generate entities and context in Entity Framework Core.

To generate entities, perform the following sequence of actions:

1.In the Model Explorer window, under Templates, select EF Core. The properties of the selected template are displayed in the Properties window:

TemplatePropertiesEFC

2.(Optional) To add serialization features, in the Serialization section of the Properties window, select the Serialization Library to use. The following serialization libraries can be used:
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.
3.(Optional) Configure other Serialization properties if necessary:
If you want to generate Serializable attributes for classes, set the Generate Serializable Attributes property to True.
If you don't want to serialize all the navigation properties, specify the corresponding value for the Serialize Navigation Properties property.
If you want to omit NULL values from serialization, set the Serialize Null Values property to False.
If you want to use database column names instead of property names in serialization, set the Serialize Original Column Names property to False.
4.(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.
5.(Optional) To implement individual Equals and GetHashCode methods for each entity class, in the Generation section of the Properties window, set the Implement Equals property to True.
6.(Optional) To implement the IValidatable interface for each entity class, in the Generation section of the Properties window, set the Implement Validatable property to True.
7.(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 property to True.
8.(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.
9.(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.
10.(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 property to True.
11. (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 property to True.
12. (Optional, for Entity Framework Core 2.0 or higher) To encapsulate the code first configuration code for each entity in a separate class, in the Configuration section of the Properties window, set the Self-Contained Entity Configuration property to True.
13. (Optional) If you did the previous step, you can change the destination folder for generated configuration classes. To do it, click the three-dotted button in the entry box of the Entities Configuration 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 Self-Contained Entity Configuration property is set to True.
14. (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.
15. (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.
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 12 of the procedure above, you will be able to select the solution project and project folder to add generated entity and configuration files instead of a file system folder.

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.