EntityTypeBuilder EntityTypeBuilder Class

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.

Syntax

Declaration

public class EntityTypeBuilder : IInfrastructure<IMutableModel>, IInfrastructure<InternalEntityTypeBuilder>Public Class EntityTypeBuilder
    Implements IInfrastructure(Of IMutableModel), IInfrastructure(Of InternalEntityTypeBuilder)

Inheritance Hierarchy

  • System.Object
    System.Object
  • EntityTypeBuilder
    EntityTypeBuilder

Inherited Members

ToString(),
ToString(),
Equals(Object),
Equals(Object),
Equals(Object, Object),
Equals(Object, Object),
ReferenceEquals(Object, Object),
ReferenceEquals(Object, Object),
GetHashCode(),
GetHashCode(),
GetType(),
GetType(),
MemberwiseClone()
MemberwiseClone()

Constructors summary

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.

Properties summary

The entity type being configured.

Methods summary

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

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.

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

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

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Explicit Interface Implementations summary

The model that the entity type belongs to.

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

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

    Property Value

Methods

  • 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

  • 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

  • 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

  • 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

  • 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

    Returns

  • 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

  • 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

  • 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

  • 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

  • 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
    • 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

    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

  • 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

  • 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
    • 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

    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

  • 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

  • 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

  • Property<TProperty>(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)

    Parameters

    • propertyName
      System.String
      System.String

      The name of the property to be configured.

    Returns

  • 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

    Returns

Explicit Interface Implementations

  • IInfrastructure<IMutableModel>.Instance
    Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.IMutableModel>.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<InternalEntityTypeBuilder>.Instance
    Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder>.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

Details

Assembly

Microsoft.EntityFrameworkCore.dll