DbContext Template

This template is designed for generating a strongly-typed DbContext class and persistence ignorant entity classes. This template is available both in C# and Visual Basic.

This template has the following properties:

Code-based Configuration

Configuration Type Name

Specifies the descendant of DbConfiguration class that should be used for code-based configuration. The special reserved value %Default% means that the standard provider-specific class will be used for .NET Core projects if possible. Accepts a class name with namespace or a fully qualified class name, including the assembly's name. An empty value means that provider registration code is not generated.

Include Environment Variables

Determines whether context configuration is extended with environment variables when a connection string from the appsettings.json file is used.

Json File Base Path

Specifies the base path for the file-based providers, when a connection string from the appsettings.json file is used. The special reserved word %CurrentDirectory% means that the current working directory of an application is used as the base path.

Use DbConfigurationType Attribute

Determines whether to register the configuration type, specified in the ConfigurationTypeName property, via the DbConfigurationType attribute. Default value is True.

Collection Properties

Collection Initialization Type

.NET Type used for initialization of the Many end of association. If it is set to None, then no initialization is generated. Acceptable values are Default, HashSet, List, None.

Collection Property Type

.NET type used as a property type for the Many end of associations. Acceptable values are Default, HashSet, ICollection, IEnumerable, IList, IReadOnlyCollection, IReadOnlyList, ISet, List, None.

Enable WinForms Data Binding

If set to True, collection properties implement the IListSource interface to enable data binding to Windows Forms (WinForms) controls in a 'master-detail' form.

Use Observable Collections

If set to True, the ObservableCollection type is generated for collection properties instead of the HashSet type.

DbContext Configuration

Auto Detect Changes Enabled

Determines whether the automatic detection of changes in the configuration is enabled. Acceptable values are True or False. Default value is True.

Proxy Creation Enabled

Determines whether the framework will create instances of dynamically generated proxy classes whenever it creates an instance of an entity type. Note that even if proxy creation is enabled, proxy instances will only be created for entity types that meet the requirements for being proxied. Acceptable values are True or False. Default value is True.

Validate On Save Enabled

Determines if tracked entities should be validated automatically when SaveChanges() is called. Acceptable values are True or False. Default value is True.

Fluent Mapping

Configurations Output

Specifies where to output the fluent mapping configuration classes. The property can be used, if Fluent Mapping, and File Per Class are turned on, and MappingGenerationStrategy = UseConfigurations.

Database Independent

If this property is set to False (default value) and the fluent mapping is used, database-specific types for entity properties and complex type properties are included to the generated code. Otherwise, the provider determines database specific types automatically and the same code can be used for different databases. Acceptable values are True or False.

Disabled Conventions

Allows you to disable Code-First configuration conventions.

0

This value indicates that no conventions are currently disabled.

AssociationInverseDiscoveryConvention

Convention to detect navigation properties to be inverses of each other when only one pair of navigation properties exists between the related types.

ColumnTypeCasingConvention

Convention to convert any data types that were explicitly specified to be lowercase.

ComplexTypeDiscoveryConvention

Convention to configure a type as a complex type if it has no primary key, no mapped base type, and no navigation properties.

DecimalPropertyConvention

Convention to set precision to 18 and scale to 2 for decimal properties.

DeclaredPropertyOrderingConvention

Convention to move primary key properties to appear first.

ForeignKeyAssociationMultiplicityConvention

Convention to distinguish between optional and required relationships based on CLR nullability of the foreign key property.

IdKeyDiscoveryConvention

Convention to detect primary key properties.

IncludeMetadataConvention

This convention determines whether it is necessary to create / use / delete the “EdmMetadata” table that stores the model hash which is used to check whether the model has changed since the database was created from it.

ManyToManyCascadeDeleteConvention

Convention to add a cascade delete to the join table from both tables involved in a many-to-many relationship.

ModelContainerConvention

This convention uses the name of the derived DbContext class as the container for the conceptual model built by Code-First.

ModelNamespaceConvention

This convention uses the namespace of the derived DbContext class as the namespace of the conceptual model built by Code-First.

namespace

Convention to discover foreign key properties whose names are a combination of the dependent navigation property name and the principal type primary key property name(s).

OneToManyCascadeDeleteConvention

Convention to enable cascade delete for any required relationships.

OneToOneConstraintIntroductionConvention

Convention to configure the primary key(s) of the dependent entity type as foreign key(s) in a one-to-one relationship.

PluralizingEntitySetNameConvention

Convention to set the entity set name to be a pluralized version of the entity type name.

PluralizingTableNameConvention

Convention to set the table name to be a pluralized version of the entity type name.

PrimaryKeyNameForeignKeyDiscoveryConvention

Convention to discover foreign key properties whose names match the principal type primary key property name(s).

PropertyMaxLengthConvention

Convention to set default maximum lengths for property types that support length facets.

StoreGeneratedIdentityKeyConvention

Convention to configure integer primary keys to be identity.

TypeNameForeignKeyDiscoveryConvention

Convention to discover foreign key properties whose names are a combination of the principal type name and the principal type primary key property name(s).

Fluent Mapping

Determines if fluent mapping is included to the generated code or XML mapping from the edml file is used. Default mapping is False, which means to use XML mapping. Acceptable values are True or False.

Mapping Generation Strategy

Determines the method of mapping generation.

UseOnModelCreatingMethod

All the fluent mapping of the model will be placed into the OnModelCreating method.

UseConfigurations

The fluent mapping for each model class will be placed to the separate configuration classes when generating code.

UseAttributes

DataAnnotation attributes will be used for defining mapping (use only for simple models).

None

No mapping will be generated (use only in cases when mapping for the model can be fully defined with default or user-defined conventions).

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

Generate Dummy Comments

Determines whether dummy XML comments will be generated for classes and their members.

Generate GeneratedCode Attributes

Determines whether the GeneratedCode attribute should be generated. It identifies code, generated by a tool, and can be used by code analysis tools to identify computer-generated code.

Header Timestamp Version Control Tag

Setting this option will replace the standard date/time stamp in the file header with the specified tag (e.g. a version control tag for Subversion, Git, etc.)

Implement Cloneable

If it is set to True, each entity class will implement the ICloneable interface. Acceptable values are True or False.

Implement Equals

Defines whether each entity class will implement its own Equals and GetHashCode methods.

Implement INotifyPropertyChanged

If it is set to True, each entity class will implement the INotifyPropertyChanged interface.

Implement INotifyPropertyChanging

If it is set to True, each entity class will implement the INotifyPropertyChanging interface.

Nullable Reference Types

Specifies when C# 8 nullable reference types and non-nullable reference types must be generated. If it is set to Enable, then nullable annotation context will be enabled. If it is set to Disable, then #'#nullable disable' directives will be generated. If it is set to Default, then pre-C# 8.0 classic behavior will be used.

Primitive Default Value Generation

Determines whether Entity Developer should generate initialization for a primitive property based on the database DEFAULT column value.

Property Change Partial Methods

Set this property to True to generate the extensibility partial void On<property name>Changing and partial void On<property name>Changed methods. These methods handle changes of each object property.

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.

Output

Context Output

Specifies output for the generated context.

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.

Entities Output

Allows specifying the output folder for the generated entity classes. The value of this property is taken into account during generation only if the File Per Class property is set to True.

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

Defines whether each model class will be placed into a separate file when generating code. Acceptable values are True or False.

Generate Partial Class

Defines whether for each class of the model a partial class will be generated, in which it will be possible to add code that won't be overwritten by the designer. The property can be used, if File Per Class is set to True. Acceptable values are True or False.

Model Name As Files Prefix

Defines whether to add the model name to the generated file names as a prefix.

 

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.

Serialize Null Values

Determines whether to serialize NULL values. For example, [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] attribute is generated for nullable properties for the Newtonsoft.Json library if this property is false. For System.Text.Json, the following attribute is generated in this case:  [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)].

Serialize Original Column Names

Determines whether to generate the original column names for serialization. For the Newtonsoft.Json library, the [JsonProperty] attribute is used. For the System.Text.Json library, the [JsonPropertyName] attribute is used. Default value is False.

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.

 


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.