EntityTypeBuilder EntityTypeBuilder Class

Definition

Provides a simple API for configuring an EntityType.

Instances of this class are returned from methods when using the ModelBuilder API and it is not designed to be directly constructed in your application code.

public class EntityTypeBuilder : IInfrastructure<IMutableModel>, IInfrastructure<InternalEntityTypeBuilder>
Public Class EntityTypeBuilder
    Implements IInfrastructure(Of IMutableModel), IInfrastructure(Of InternalEntityTypeBuilder)
Inheritance
System.ObjectSystem.Object
EntityTypeBuilderEntityTypeBuilder
Implements

Constructors

EntityTypeBuilder(InternalEntityTypeBuilder) EntityTypeBuilder(InternalEntityTypeBuilder)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

public EntityTypeBuilder(InternalEntityTypeBuilder builder)
Public Sub New(builder As InternalEntityTypeBuilder)
Parameters

Properties

Metadata Metadata

The entity type being configured.

public virtual IMutableEntityType Metadata { get; }
Public Overridable ReadOnly Property Metadata As IMutableEntityType

Methods

Equals(Object) Equals(Object)

Inherited from System.Object

Equals(Object, Object) Equals(Object, Object)

Inherited from System.Object

GetHashCode() GetHashCode()

Inherited from System.Object

GetType() GetType()

Inherited from System.Object

HasAlternateKey(String[]) HasAlternateKey(String())

Creates a new unique constraint for this entity type if one does not already exist over the specified properties.

public virtual KeyBuilder HasAlternateKey(params string[] propertyNames)
Public Overridable Function HasAlternateKey(ParamArray propertyNames As String()) As KeyBuilder
Parameters
propertyNames
System.String[] System.String()

The names of the properties that make up the unique constraint.

Returns

An object that can be used to configure the unique constraint.

HasAnnotation(String, Object) HasAnnotation(String, Object)

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

public virtual EntityTypeBuilder HasAnnotation(string annotation, object value)
Public Overridable Function HasAnnotation(annotation As String, value As Object) As EntityTypeBuilder
Parameters
annotation
System.String System.String

The key of the annotation to be added or updated.

value
System.Object System.Object

The value to be stored in the annotation.

Returns

The same builder instance so that multiple configuration calls can be chained.

HasBaseType(String) HasBaseType(String)

Sets the base type of this entity in an inheritance hierarchy.

public virtual EntityTypeBuilder HasBaseType(string name)
Public Overridable Function HasBaseType(name As String) As EntityTypeBuilder
Parameters
name
System.String System.String

The name of the base type.

Returns

The same builder instance so that multiple configuration calls can be chained.

HasBaseType(Type) HasBaseType(Type)

Sets the base type of this entity in an inheritance hierarchy.

public virtual EntityTypeBuilder HasBaseType(Type entityType)
Public Overridable Function HasBaseType(entityType As Type) As EntityTypeBuilder
Parameters
entityType
System.Type System.Type

The base type.

Returns

The same builder instance so that multiple configuration calls can be chained.

HasChangeTrackingStrategy(ChangeTrackingStrategy) HasChangeTrackingStrategy(ChangeTrackingStrategy)

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

public virtual EntityTypeBuilder HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)
Public Overridable Function HasChangeTrackingStrategy(changeTrackingStrategy As ChangeTrackingStrategy) As EntityTypeBuilder
Parameters
changeTrackingStrategy
ChangeTrackingStrategy ChangeTrackingStrategy

The change tracking strategy to be used.

Returns

The same builder instance so that multiple configuration calls can be chained.

HasIndex(String[]) HasIndex(String())

Configures an index on the specified properties. If there is an existing index on the given set of properties, then the existing index will be returned for configuration.

public virtual IndexBuilder HasIndex(params string[] propertyNames)
Public Overridable Function HasIndex(ParamArray propertyNames As String()) As IndexBuilder
Parameters
propertyNames
System.String[] System.String()

The names of the properties that make up the index.

Returns

An object that can be used to configure the index.

HasKey(String[]) HasKey(String())

Sets the properties that make up the primary key for this entity type.

public virtual KeyBuilder HasKey(params string[] propertyNames)
Public Overridable Function HasKey(ParamArray propertyNames As String()) As KeyBuilder
Parameters
propertyNames
System.String[] System.String()

The names of the properties that make up the primary key.

Returns

An object that can be used to configure the primary key.

HasMany(String, String) HasMany(String, String)

Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship.

After calling this method, you should chain a call to WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual CollectionNavigationBuilder HasMany(string relatedTypeName, string navigationName = null)
Public Overridable Function HasMany(relatedTypeName As String, navigationName As String = Nothing) As CollectionNavigationBuilder
Parameters
relatedTypeName
System.String System.String

The name of the entity type that this relationship targets.

navigationName
System.String System.String

The name of the collection navigation property on this entity type that represents the relationship. If no property is specified, the relationship will be configured without a navigation property on this end.

Returns

An object that can be used to configure the relationship.

HasMany(Type, String) HasMany(Type, String)

Configures a relationship where this entity type has a collection that contains instances of the other type in the relationship.

After calling this method, you should chain a call to WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual CollectionNavigationBuilder HasMany(Type relatedType, string navigationName = null)
Public Overridable Function HasMany(relatedType As Type, navigationName As String = Nothing) As CollectionNavigationBuilder
Parameters
relatedType
System.Type System.Type

The entity type that this relationship targets.

navigationName
System.String System.String

The name of the collection navigation property on this entity type that represents the relationship. If no property is specified, the relationship will be configured without a navigation property on this end.

Returns

An object that can be used to configure the relationship.

HasManyBuilder(EntityType, PropertyInfo) HasManyBuilder(EntityType, PropertyInfo)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

protected virtual InternalRelationshipBuilder HasManyBuilder(EntityType relatedEntityType, PropertyInfo navigationProperty)
Protected Overridable Function HasManyBuilder(relatedEntityType As EntityType, navigationProperty As PropertyInfo) As InternalRelationshipBuilder
Parameters
relatedEntityType
EntityType EntityType
navigationProperty
System.Reflection.PropertyInfo System.Reflection.PropertyInfo
Returns

HasManyBuilder(EntityType, String) HasManyBuilder(EntityType, String)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

protected virtual InternalRelationshipBuilder HasManyBuilder(EntityType relatedEntityType, string navigationName)
Protected Overridable Function HasManyBuilder(relatedEntityType As EntityType, navigationName As String) As InternalRelationshipBuilder
Parameters
relatedEntityType
EntityType EntityType
navigationName
System.String System.String
Returns

HasOne(String, String) HasOne(String, String)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

After calling this method, you should chain a call to WithMany(String) or WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual ReferenceNavigationBuilder HasOne(string relatedTypeName, string navigationName = null)
Public Overridable Function HasOne(relatedTypeName As String, navigationName As String = Nothing) As ReferenceNavigationBuilder
Parameters
relatedTypeName
System.String System.String

The name of the entity type that this relationship targets.

navigationName
System.String System.String

The name of the reference navigation property on this entity type that represents the relationship. If no property is specified, the relationship will be configured without a navigation property on this end.

Returns

An object that can be used to configure the relationship.

HasOne(Type, String) HasOne(Type, String)

Configures a relationship where this entity type has a reference that points to a single instance of the other type in the relationship.

After calling this method, you should chain a call to WithMany(String) or WithOne(String) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

public virtual ReferenceNavigationBuilder HasOne(Type relatedType, string navigationName = null)
Public Overridable Function HasOne(relatedType As Type, navigationName As String = Nothing) As ReferenceNavigationBuilder
Parameters
relatedType
System.Type System.Type

The entity type that this relationship targets.

navigationName
System.String System.String

The name of the reference navigation property on this entity type that represents the relationship. If no property is specified, the relationship will be configured without a navigation property on this end.

Returns

An object that can be used to configure the relationship.

HasOneBuilder(EntityType, PropertyInfo) HasOneBuilder(EntityType, PropertyInfo)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

protected virtual InternalRelationshipBuilder HasOneBuilder(EntityType relatedEntityType, PropertyInfo navigationProperty)
Protected Overridable Function HasOneBuilder(relatedEntityType As EntityType, navigationProperty As PropertyInfo) As InternalRelationshipBuilder
Parameters
relatedEntityType
EntityType EntityType
navigationProperty
System.Reflection.PropertyInfo System.Reflection.PropertyInfo
Returns

HasOneBuilder(EntityType, String) HasOneBuilder(EntityType, String)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

protected virtual InternalRelationshipBuilder HasOneBuilder(EntityType relatedEntityType, string navigationName)
Protected Overridable Function HasOneBuilder(relatedEntityType As EntityType, navigationName As String) As InternalRelationshipBuilder
Parameters
relatedEntityType
EntityType EntityType
navigationName
System.String System.String
Returns

Ignore(String) Ignore(String)

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

public virtual EntityTypeBuilder Ignore(string propertyName)
Public Overridable Function Ignore(propertyName As String) As EntityTypeBuilder
Parameters
propertyName
System.String System.String

The name of then property to be removed from the entity type.

Returns

MemberwiseClone() MemberwiseClone()

Inherited from System.Object

New(InternalEntityTypeBuilder) New(InternalEntityTypeBuilder)

This API supports the Entity Framework Core infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

protected virtual EntityTypeBuilder New(InternalEntityTypeBuilder builder)
Protected Overridable Function New(builder As InternalEntityTypeBuilder) As EntityTypeBuilder
Parameters
Returns

Property(String) Property(String)

Returns an object that can be used to configure a property of the entity type. If no property with the given name exists, then a new property will be added.

When adding a new property with this overload the property name must match the name of a CLR property or field on the entity type. This overload cannot be used to add a new shadow state property.

public virtual PropertyBuilder Property(string propertyName)
Public Overridable Function Property(propertyName As String) As PropertyBuilder
Parameters
propertyName
System.String System.String

The name of the property to be configured.

Returns

An object that can be used to configure the property.

Property(Type, String) Property(Type, String)

Returns an object that can be used to configure a property of the entity type. If no property with the given name exists, then a new property will be added.

When adding a new property, if a property with the same name exists in the entity class then it will be added to the model. If no property exists in the entity class, then a new shadow state property will be added. A shadow state property is one that does not have a corresponding property in the entity class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the entity class.

public virtual PropertyBuilder Property(Type propertyType, string propertyName)
Public Overridable Function Property(propertyType As Type, propertyName As String) As PropertyBuilder
Parameters
propertyType
System.Type System.Type

The type of the property to be configured.

propertyName
System.String System.String

The name of the property to be configured.

Returns

An object that can be used to configure the property.

Property(String) Property(Of TProperty)(String)

Returns an object that can be used to configure a property of the entity type. If no property with the given name exists, then a new property will be added.

When adding a new property, if a property with the same name exists in the entity class then it will be added to the model. If no property exists in the entity class, then a new shadow state property will be added. A shadow state property is one that does not have a corresponding property in the entity class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the entity class.

public virtual PropertyBuilder<TProperty> Property<TProperty>(string propertyName)
Public Overridable Function Property(Of TProperty)(propertyName As String) As PropertyBuilder(Of TProperty)
Type Parameters
TProperty

The type of the property to be configured.

Parameters
propertyName
System.String System.String

The name of the property to be configured.

Returns
PropertyBuilder<TProperty> PropertyBuilder(Of TProperty)

An object that can be used to configure the property.

ReferenceEquals(Object, Object) ReferenceEquals(Object, Object)

Inherited from System.Object

ToString() ToString()

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 of this entity type as described in the PropertyAccessMode enum.

Calling this method overrrides for all properties of this entity type any access mode that was set on the model.

public virtual EntityTypeBuilder UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)
Public Overridable Function UsePropertyAccessMode(propertyAccessMode As PropertyAccessMode) As EntityTypeBuilder
Parameters
propertyAccessMode
PropertyAccessMode PropertyAccessMode

The PropertyAccessMode to use for properties of this entity type.

Returns

The same builder instance so that multiple configuration calls can be chained.

Explicit Interface Implementations

IInfrastructure.Instance Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure.Instance

The model that the entity type belongs to.

IMutableModel IInfrastructure<IMutableModel>.Instance { get; }
ReadOnly WriteOnly Property Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.IMutableModel>.Instance As IMutableModel Implements IInfrastructure(Of IMutableModel).Instance
Returns

IInfrastructure.Instance Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure.Instance

Gets the internal builder being used to configure the entity type.

InternalEntityTypeBuilder IInfrastructure<InternalEntityTypeBuilder>.Instance { get; }
ReadOnly WriteOnly Property Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder>.Instance As InternalEntityTypeBuilder Implements IInfrastructure(Of InternalEntityTypeBuilder).Instance
Returns