Table of Contents

Class ModelConfigurationBuilder

Namespace
Microsoft.EntityFrameworkCore
Assembly
Microsoft.EntityFrameworkCore.dll

Provides a simple API surface for setting defaults and configuring conventions before they run.

public class ModelConfigurationBuilder
Inheritance
ModelConfigurationBuilder
Inherited Members

Remarks

You can use ModelConfigurationBuilder to configure the conventions for a context by overriding ConfigureConventions(ModelConfigurationBuilder) on your derived context. Alternatively you can create the model externally and set it on a DbContextOptions instance that is passed to the context constructor.

See Pre-convention model building in EF Core for more information and examples.

Constructors

ModelConfigurationBuilder(ConventionSet, IServiceProvider)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

[EntityFrameworkInternal]
public ModelConfigurationBuilder(ConventionSet conventions, IServiceProvider serviceProvider)

Parameters

conventions ConventionSet
serviceProvider IServiceProvider

Properties

Conventions

Gets the builder for the conventions that will be used in the model.

public virtual ConventionSetBuilder Conventions { get; }

Property Value

ConventionSetBuilder

ModelConfiguration

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

[EntityFrameworkInternal]
protected virtual ModelConfiguration ModelConfiguration { get; }

Property Value

ModelConfiguration

Methods

ComplexProperties(Type)

Marks the given and derived types as corresponding to complex properties.

public virtual ComplexPropertiesConfigurationBuilder ComplexProperties(Type propertyType)

Parameters

propertyType Type

The property type to be configured.

Returns

ComplexPropertiesConfigurationBuilder

An object that can be used to configure the property.

Remarks

This can also be called on an interface or an unbound generic type to apply the configuration to all properties of implementing and constructed types.

See Pre-convention model building in EF Core for more information and examples.

ComplexProperties<TProperty>()

Marks the given and derived types as corresponding to complex properties.

public virtual ComplexPropertiesConfigurationBuilder<TProperty> ComplexProperties<TProperty>()

Returns

ComplexPropertiesConfigurationBuilder<TProperty>

An object that can be used to configure the properties.

Type Parameters

TProperty

The property type to be configured.

Remarks

This can also be called on an interface to apply the configuration to all properties of implementing types.

See Pre-convention model building in EF Core for more information and examples.

CreateModelBuilder(ModelDependencies?)

Creates the configured ModelBuilder used to create the model. This is done automatically when using OnModelCreating(ModelBuilder); this method allows it to be run explicitly in cases where the automatic execution is not possible.

public virtual ModelBuilder CreateModelBuilder(ModelDependencies? modelDependencies)

Parameters

modelDependencies ModelDependencies

The dependencies object used during model building.

Returns

ModelBuilder

The configured ModelBuilder.

Remarks

See Pre-convention model building in EF Core for more information and examples.

DefaultTypeMapping(Type)

Marks the given type as a scalar, even when used outside of entity types. This allows values of this type to be used in queries that are not referencing property of this type.

public virtual TypeMappingConfigurationBuilder DefaultTypeMapping(Type scalarType)

Parameters

scalarType Type

The scalar type to be configured.

Returns

TypeMappingConfigurationBuilder

An object that can be used to configure the scalars.

Remarks

Unlike Properties(Type) this method should only be called on a non-nullable concrete type. Calling it on a base type will not apply the configuration to the derived types.

Calling this is rarely needed. If there are properties of the given type calling Properties(Type) should be enough in most cases.

See Pre-convention model building in EF Core for more information and examples.

DefaultTypeMapping(Type, Action<TypeMappingConfigurationBuilder>)

Marks the given type as a scalar, even when used outside of entity types. This allows values of this type to be used in queries that are not referencing property of this type.

public virtual ModelConfigurationBuilder DefaultTypeMapping(Type scalarType, Action<TypeMappingConfigurationBuilder> buildAction)

Parameters

scalarType Type

The scalar type to be configured.

buildAction Action<TypeMappingConfigurationBuilder>

An action that performs configuration for the scalars.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Remarks

Unlike Properties(Type) this method should only be called on a non-nullable concrete type. Calling it on a base type will not apply the configuration to the derived types.

Calling this is rarely needed. If there are properties of the given type calling Properties(Type) should be enough in most cases.

See Pre-convention model building in EF Core for more information and examples.

DefaultTypeMapping<TScalar>()

Marks the given type as a scalar, even when used outside of entity types. This allows values of this type to be used in queries that are not referencing property of this type.

public virtual TypeMappingConfigurationBuilder<TScalar> DefaultTypeMapping<TScalar>()

Returns

TypeMappingConfigurationBuilder<TScalar>

An object that can be used to configure the scalars.

Type Parameters

TScalar

The scalar type to be configured.

Remarks

Unlike Properties<TProperty>() this method should only be called on a non-nullable concrete type. Calling it on a base type will not apply the configuration to the derived types.

Calling this is rarely needed. If there are properties of the given type calling Properties<TProperty>() should be enough in most cases.

See Pre-convention model building in EF Core for more information and examples.

DefaultTypeMapping<TScalar>(Action<TypeMappingConfigurationBuilder<TScalar>>)

Marks the given type as a scalar, even when used outside of entity types. This allows values of this type to be used in queries that are not referencing property of this type.

public virtual ModelConfigurationBuilder DefaultTypeMapping<TScalar>(Action<TypeMappingConfigurationBuilder<TScalar>> buildAction)

Parameters

buildAction Action<TypeMappingConfigurationBuilder<TScalar>>

An action that performs configuration for the scalars.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Type Parameters

TScalar

The scalar type to be configured.

Remarks

Unlike Properties<TProperty>() this method should only be called on a non-nullable concrete type. Calling it on a base type will not apply the configuration to the derived types.

Calling this is rarely needed. If there are properties of the given type calling Properties<TProperty>() should be enough in most cases.

See Pre-convention model building in EF Core for more information and examples.

IgnoreAny(Type)

Prevents the conventions from the given type from discovering properties of the given or derived types.

public virtual ModelConfigurationBuilder IgnoreAny(Type type)

Parameters

type Type

The type to be ignored.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Remarks

See Pre-convention model building in EF Core for more information and examples.

IgnoreAny<T>()

Prevents the conventions from the given type from discovering properties of the given or derived types.

public virtual ModelConfigurationBuilder IgnoreAny<T>()

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Type Parameters

T

The type to be ignored.

Remarks

See Pre-convention model building in EF Core for more information and examples.

Properties(Type)

Marks the given and derived types as corresponding to entity type properties.

public virtual PropertiesConfigurationBuilder Properties(Type propertyType)

Parameters

propertyType Type

The property type to be configured.

Returns

PropertiesConfigurationBuilder

An object that can be used to configure the property.

Remarks

This can also be called on an interface or an unbound generic type to apply the configuration to all properties of implementing and constructed types.

See Pre-convention model building in EF Core for more information and examples.

Properties(Type, Action<PropertiesConfigurationBuilder>)

Marks the given and derived types as corresponding to entity type properties.

public virtual ModelConfigurationBuilder Properties(Type propertyType, Action<PropertiesConfigurationBuilder> buildAction)

Parameters

propertyType Type

The property type to be configured.

buildAction Action<PropertiesConfigurationBuilder>

An action that performs configuration of the property.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Remarks

This can also be called on an interface or an unbound generic type to apply the configuration to all properties of implementing and constructed types.

See Pre-convention model building in EF Core for more information and examples.

Properties<TProperty>()

Marks the given and derived types as corresponding to entity type properties.

public virtual PropertiesConfigurationBuilder<TProperty> Properties<TProperty>()

Returns

PropertiesConfigurationBuilder<TProperty>

An object that can be used to configure the properties.

Type Parameters

TProperty

The property type to be configured.

Remarks

This can also be called on an interface to apply the configuration to all properties of implementing types.

See Pre-convention model building in EF Core for more information and examples.

Properties<TProperty>(Action<PropertiesConfigurationBuilder<TProperty>>)

Marks the given and derived types as corresponding to entity type properties.

public virtual ModelConfigurationBuilder Properties<TProperty>(Action<PropertiesConfigurationBuilder<TProperty>> buildAction)

Parameters

buildAction Action<PropertiesConfigurationBuilder<TProperty>>

An action that performs configuration of the property.

Returns

ModelConfigurationBuilder

The same ModelConfigurationBuilder instance so that additional configuration calls can be chained.

Type Parameters

TProperty

The property type to be configured.

Remarks

This can also be called on an interface to apply the configuration to all properties of implementing types.

See Pre-convention model building in EF Core for more information and examples.