ModelBuilder ModelBuilder Class

Definition

Provides a simple API surface for configuring a IMutableModel that defines the shape of your entities, the relationships between them, and how they map to the database.

You can use ModelBuilder to construct a model for a context by overriding OnModelCreating(ModelBuilder) 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.

public class ModelBuilder : IInfrastructure<InternalModelBuilder>
Public Class ModelBuilder
    Implements IInfrastructure(Of InternalModelBuilder)
Inheritance
System.ObjectSystem.Object
ModelBuilderModelBuilder
Implements

Constructors

ModelBuilder(ConventionSet) ModelBuilder(ConventionSet)

Initializes a new instance of the ModelBuilder class that will apply a set of conventions.

Properties

Model Model

The model being configured.

Methods

Entity(String) Entity(String)

Returns an object that can be used to configure a given entity type in the model. If an entity type with the provided name is not already part of the model, a new entity type that does not have a corresponding CLR type will be added to the model.

Entity(String, Action<EntityTypeBuilder>) Entity(String, Action(Of EntityTypeBuilder))

Performs configuration of a given entity type in the model. If an entity type with the provided name is not already part of the model, a new entity type that does not have a corresponding CLR type will be added to the model.

This overload allows configuration of the entity type to be done in line in the method call rather than being chained after a call to Entity(String). This allows additional configuration at the model level to be chained after configuration for the entity type.

Entity(Type) Entity(Type)

Returns an object that can be used to configure a given entity type in the model. If the entity type is not already part of the model, it will be added to the model.

Entity(Type, Action<EntityTypeBuilder>) Entity(Type, Action(Of EntityTypeBuilder))

Performs configuration of a given entity type in the model. If the entity type is not already part of the model, it will be added to the model.

This overload allows configuration of the entity type to be done in line in the method call rather than being chained after a call to Entity<TEntity>(). This allows additional configuration at the model level to be chained after configuration for the entity type.

Entity<TEntity>(Action<EntityTypeBuilder<TEntity>>) Entity(Of TEntity)(Action(Of EntityTypeBuilder(Of TEntity)))

Performs configuration of a given entity type in the model. If the entity type is not already part of the model, it will be added to the model.

This overload allows configuration of the entity type to be done in line in the method call rather than being chained after a call to Entity<TEntity>(). This allows additional configuration at the model level to be chained after configuration for the entity type.

System.Object.Equals(System.Object) System.Object.Equals(System.Object) Inherited from System.Object
System.Object.Equals(System.Object, System.Object) System.Object.Equals(System.Object, System.Object) Inherited from System.Object
System.Object.GetHashCode() System.Object.GetHashCode() Inherited from System.Object
System.Object.GetType() System.Object.GetType() Inherited from System.Object
HasAnnotation(String, Object) HasAnnotation(String, Object)

Adds or updates an annotation on the model. If an annotation with the key specified in annotation already exists it's value will be updated.

HasChangeTrackingStrategy(ChangeTrackingStrategy) HasChangeTrackingStrategy(ChangeTrackingStrategy)

Configures the default ChangeTrackingStrategy to be used for this model. This strategy indicates how the context detects changes to properties for an instance of an entity type.

Ignore(Type) Ignore(Type)

Excludes the given entity type from the model. This method is typically used to remove types from the model that were added by convention.

Ignore<TEntity>() Ignore(Of TEntity)()

Excludes the given entity type from the model. This method is typically used to remove types from the model that were added by convention.

System.Object.ReferenceEquals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) Inherited from System.Object
UsePropertyAccessMode(PropertyAccessMode) UsePropertyAccessMode(PropertyAccessMode)

Sets the PropertyAccessMode to use for all properties of this entity type.

By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method witll change that behavior for all properties in the model as described in the PropertyAccessMode enum.

Entity<TEntity>() Entity<TEntity>()

Returns an object that can be used to configure a given entity type in the model. If the entity type is not already part of the model, it will be added to the model.

System.Object.MemberwiseClone() System.Object.MemberwiseClone() Inherited from System.Object
System.Object.ToString() System.Object.ToString() Inherited from System.Object

Explicit Interface Implementations

IInfrastructure<InternalModelBuilder>.Instance Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder>.Instance

The internal ModelBuilder being used to configure this model.

This property is intended for use by extension methods to configure the model. It is not intended to be used in application code.

Extension Methods

Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.String) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.String)
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence<T>(System.String, System.String) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(Of T)(System.String, System.String)
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence<T>(System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(Of T)(System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence<T>(System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(Of T)(System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.String) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.String)
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerHasSequence(System.Type, System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerUseSequenceHiLo(System.String, System.String) Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerUseSequenceHiLo(System.String, System.String)
Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerUseIdentityColumns() Microsoft.EntityFrameworkCore.SqlServerModelBuilderExtensions.ForSqlServerUseIdentityColumns()
Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder>() Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetInfrastructure(Of Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder)()
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.String) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.String)
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.String) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.String)
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(System.Type, System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence<T>(System.String, System.String) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(Of T)(System.String, System.String)
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence<T>(System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(Of T)(System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence<T>(System.String, System.String, System.Action<RelationalSequenceBuilder>) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasSequence(Of T)(System.String, System.String, System.Action(Of RelationalSequenceBuilder))
Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasDefaultSchema(System.String) Microsoft.EntityFrameworkCore.RelationalModelBuilderExtensions.HasDefaultSchema(System.String)