EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity) 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<TEntity> : EntityTypeBuilder, IInfrastructure<IMutableModel>, IInfrastructure<InternalEntityTypeBuilder> where TEntity : classPublic Class EntityTypeBuilder(Of TEntity As Class)
    Inherits EntityTypeBuilder
    Implements IInfrastructure(Of IMutableModel), IInfrastructure(Of InternalEntityTypeBuilder)

Type Parameters

TEntity The entity type being configured.

Inheritance Hierarchy

Inherited Members

IInfrastructure<InternalEntityTypeBuilder>.Instance,
Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder>.Instance,
Metadata,
Metadata,
IInfrastructure<IMutableModel>.Instance,
Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.IMutableModel>.Instance,
HasKey(String[]),
HasKey(String()),
HasAlternateKey(String[]),
HasAlternateKey(String()),
Property<TProperty>(String),
Property(Of TProperty)(String),
Property(Type, String),
Property(Type, String),
Property(String),
Property(String),
HasIndex(String[]),
HasIndex(String()),
HasOne(Type, String),
HasOne(Type, String),
HasOne(String, String),
HasOne(String, String),
HasMany(Type, String),
HasMany(Type, String),
HasMany(String, String),
HasMany(String, String),
HasOneBuilder(EntityType, String),
HasOneBuilder(EntityType, String),
HasOneBuilder(EntityType, PropertyInfo),
HasOneBuilder(EntityType, PropertyInfo),
HasManyBuilder(EntityType, String),
HasManyBuilder(EntityType, String),
HasManyBuilder(EntityType, PropertyInfo),
HasManyBuilder(EntityType, PropertyInfo),
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.

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.

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(Expression<Func<TRelatedEntity, TEntity>>) 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(Expression<Func<TRelatedEntity, IEnumerable<TEntity>>>) or WithOne(Expression<Func<TRelatedEntity, TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

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.

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.

Creates a new builder based on the provided internal builder. This overridden implementation creates

EntityTypeBuilder<TEntity> instances so that logic inherited from the base class will use those instead of EntityTypeBuilder.

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

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.

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

Methods

  • HasAlternateKey(Expression<Func<TEntity, Object>>)
    HasAlternateKey(Expression(Of Func(Of TEntity, Object)))

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

    public virtual KeyBuilder HasAlternateKey(Expression<Func<TEntity, object>> keyExpression)Public Overridable Function HasAlternateKey(keyExpression As Expression(Of Func(Of TEntity, Object))) As KeyBuilder

    Parameters

    • keyExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, System.Object>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, System.Object))

      A lambda expression representing the unique constraint property(s) (blog => blog.Url).

      If the unique constraint is made up of multiple properties then specify an anonymous type including the properties (post => new { post.Title, post.BlogId }).

    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<TEntity> HasAnnotation(string annotation, object value)Public Overridable Function HasAnnotation(annotation As String, value As Object) As EntityTypeBuilder(Of TEntity)

    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<TEntity> HasBaseType(string name)Public Overridable Function HasBaseType(name As String) As EntityTypeBuilder(Of TEntity)

    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<TEntity> HasBaseType(Type entityType)Public Overridable Function HasBaseType(entityType As Type) As EntityTypeBuilder(Of TEntity)

    Parameters

    • entityType
      System.Type
      System.Type

      The base type.

    Returns

  • HasBaseType<TBaseType>()
    HasBaseType(Of TBaseType)()

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

    public virtual EntityTypeBuilder<TEntity> HasBaseType<TBaseType>()Public Overridable Function HasBaseType(Of TBaseType) As EntityTypeBuilder(Of TEntity)

    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<TEntity> HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)Public Overridable Function HasChangeTrackingStrategy(changeTrackingStrategy As ChangeTrackingStrategy) As EntityTypeBuilder(Of TEntity)

    Parameters

    Returns

  • HasIndex(Expression<Func<TEntity, Object>>)
    HasIndex(Expression(Of Func(Of TEntity, Object)))

    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(Expression<Func<TEntity, object>> indexExpression)Public Overridable Function HasIndex(indexExpression As Expression(Of Func(Of TEntity, Object))) As IndexBuilder

    Parameters

    • indexExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, System.Object>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, System.Object))

      A lambda expression representing the property(s) to be included in the index (blog => blog.Url).

      If the index is made up of multiple properties then specify an anonymous type including the properties (post => new { post.Title, post.BlogId }).

    Returns

  • HasKey(Expression<Func<TEntity, Object>>)
    HasKey(Expression(Of Func(Of TEntity, Object)))

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

    public virtual KeyBuilder HasKey(Expression<Func<TEntity, object>> keyExpression)Public Overridable Function HasKey(keyExpression As Expression(Of Func(Of TEntity, Object))) As KeyBuilder

    Parameters

    • keyExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, System.Object>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, System.Object))

      A lambda expression representing the primary key property(s) (blog => blog.Url).

      If the primary key is made up of multiple properties then specify an anonymous type including the properties (post => new { post.Title, post.BlogId }).

    Returns

  • HasMany<TRelatedEntity>(Expression<Func<TEntity, IEnumerable<TRelatedEntity>>>)
    HasMany(Of TRelatedEntity)(Expression(Of Func(Of TEntity, IEnumerable(Of TRelatedEntity))))

    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(Expression<Func<TRelatedEntity, TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

    public virtual CollectionNavigationBuilder<TEntity, TRelatedEntity> HasMany<TRelatedEntity>(Expression<Func<TEntity, IEnumerable<TRelatedEntity>>> navigationExpression = null)where TRelatedEntity : classPublic Overridable Function HasMany(Of TRelatedEntity As Class)(navigationExpression As Expression(Of Func(Of TEntity, IEnumerable(Of TRelatedEntity))) = Nothing) As CollectionNavigationBuilder(Of TEntity, TRelatedEntity)

    Parameters

    • navigationExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, System.Collections.Generic.IEnumerable<T><TRelatedEntity>>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, System.Collections.Generic.IEnumerable<T>(Of TRelatedEntity)))

      A lambda expression representing the collection navigation property on this entity type that represents the relationship (blog => blog.Posts). If no property is specified, the relationship will be configured without a navigation property on this end.

    Returns

  • HasOne<TRelatedEntity>(Expression<Func<TEntity, TRelatedEntity>>)
    HasOne(Of TRelatedEntity)(Expression(Of Func(Of TEntity, TRelatedEntity)))

    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(Expression<Func<TRelatedEntity, IEnumerable<TEntity>>>) or WithOne(Expression<Func<TRelatedEntity, TEntity>>) to fully configure the relationship. Calling just this method without the chained call will not produce a valid relationship.

    public virtual ReferenceNavigationBuilder<TEntity, TRelatedEntity> HasOne<TRelatedEntity>(Expression<Func<TEntity, TRelatedEntity>> navigationExpression = null)where TRelatedEntity : classPublic Overridable Function HasOne(Of TRelatedEntity As Class)(navigationExpression As Expression(Of Func(Of TEntity, TRelatedEntity)) = Nothing) As ReferenceNavigationBuilder(Of TEntity, TRelatedEntity)

    Parameters

    • navigationExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, TRelatedEntity>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, TRelatedEntity))

      A lambda expression representing the reference navigation property on this entity type that represents the relationship (post => post.Blog). If no property is specified, the relationship will be configured without a navigation property on this end.

    Returns

  • Ignore(Expression<Func<TEntity, Object>>)
    Ignore(Expression(Of Func(Of TEntity, Object)))

    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<TEntity> Ignore(Expression<Func<TEntity, object>> propertyExpression)Public Overridable Function Ignore(propertyExpression As Expression(Of Func(Of TEntity, Object))) As EntityTypeBuilder(Of TEntity)

    Parameters

    • propertyExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, System.Object>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, System.Object))

      A lambda expression representing the property to be ignored (blog => blog.Url).

    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<TEntity> Ignore(string propertyName)Public Overridable Function Ignore(propertyName As String) As EntityTypeBuilder(Of TEntity)

    Parameters

    • propertyName
      System.String
      System.String

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

    Returns

  • New(InternalEntityTypeBuilder)
    New(InternalEntityTypeBuilder)

    Creates a new builder based on the provided internal builder. This overridden implementation creates

    EntityTypeBuilder<TEntity> instances so that logic inherited from the base class will use those instead of EntityTypeBuilder.

    protected override EntityTypeBuilder New(InternalEntityTypeBuilder builder)Protected Overrides Function New(builder As InternalEntityTypeBuilder) As EntityTypeBuilder

    Parameters

    Returns

  • Property<TProperty>(Expression<Func<TEntity, TProperty>>)
    Property(Of TProperty)(Expression(Of Func(Of TEntity, TProperty)))

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

    public virtual PropertyBuilder<TProperty> Property<TProperty>(Expression<Func<TEntity, TProperty>> propertyExpression)Public Overridable Function Property(Of TProperty)(propertyExpression As Expression(Of Func(Of TEntity, TProperty))) As PropertyBuilder(Of TProperty)

    Parameters

    • propertyExpression
      System.Linq.Expressions.Expression<TDelegate><System.Func<T, TResult><TEntity, TProperty>>
      System.Linq.Expressions.Expression<TDelegate>(Of System.Func<T, TResult>(Of TEntity, TProperty))

      A lambda expression representing the property to be configured ( blog => blog.Url).

    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<TEntity> UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)Public Overridable Function UsePropertyAccessMode(propertyAccessMode As PropertyAccessMode) As EntityTypeBuilder(Of TEntity)

    Parameters

    Returns

Details

Assembly

Microsoft.EntityFrameworkCore.dll