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

The entity type being configured.

Inheritance
System.ObjectSystem.Object
EntityTypeBuilder<TEntity>EntityTypeBuilder(Of TEntity)
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

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(Expression<>>) 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<System.Func<TEntity, System.Object>> System.Linq.Expressions.Expression(Of System.Func(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

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

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

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

(Inherited from EntityTypeBuilder)

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
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

The same typeBuilder 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<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
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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<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
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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

HasBaseType() 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)
Type Parameters
TBaseType

The base type.

Returns
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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

The change tracking strategy to be used.

Returns
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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

HasIndex(Expression<>>) 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<System.Func<TEntity, System.Object>> System.Linq.Expressions.Expression(Of System.Func(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

An object that can be used to configure the index.

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.

(Inherited from EntityTypeBuilder)

HasKey(Expression<>>) 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<System.Func<TEntity, System.Object>> System.Linq.Expressions.Expression(Of System.Func(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

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

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

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

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

HasMany(Expression<>>>) 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 : class
Public Overridable Function HasMany(Of TRelatedEntity As Class)(navigationExpression As Expression(Of Func(Of TEntity, IEnumerable(Of TRelatedEntity))) = Nothing) As CollectionNavigationBuilder(Of TEntity, TRelatedEntity)
Type Parameters
TRelatedEntity

The entity type that this relationship targets.

Parameters
navigationExpression
System.Linq.Expressions.Expression<System.Func<TEntity, System.Collections.Generic.IEnumerable<TRelatedEntity>>> System.Linq.Expressions.Expression(Of System.Func(Of TEntity, System.Collections.Generic.IEnumerable(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
CollectionNavigationBuilder<TEntity, TRelatedEntity> CollectionNavigationBuilder(Of TEntity, TRelatedEntity)

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

HasOne(Expression<>>) 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 : class
Public Overridable Function HasOne(Of TRelatedEntity As Class)(navigationExpression As Expression(Of Func(Of TEntity, TRelatedEntity)) = Nothing) As ReferenceNavigationBuilder(Of TEntity, TRelatedEntity)
Type Parameters
TRelatedEntity

The entity type that this relationship targets.

Parameters
navigationExpression
System.Linq.Expressions.Expression<System.Func<TEntity, TRelatedEntity>> System.Linq.Expressions.Expression(Of System.Func(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
ReferenceNavigationBuilder<TEntity, TRelatedEntity> ReferenceNavigationBuilder(Of TEntity, TRelatedEntity)

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

Ignore(Expression<>>) 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<System.Func<TEntity, System.Object>> System.Linq.Expressions.Expression(Of System.Func(Of TEntity, System.Object))

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

Returns
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

MemberwiseClone() MemberwiseClone()

Inherited from System.Object

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
builder
InternalEntityTypeBuilder InternalEntityTypeBuilder

The internal builder to create the new builder from.

Returns

The newly created builder.

Overrides

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.

(Inherited from EntityTypeBuilder)

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.

(Inherited from EntityTypeBuilder)

Property(Expression<>>) 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)
Type Parameters
TProperty
Parameters
propertyExpression
System.Linq.Expressions.Expression<System.Func<TEntity, TProperty>> System.Linq.Expressions.Expression(Of System.Func(Of TEntity, TProperty))

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

Returns
PropertyBuilder<TProperty> PropertyBuilder(Of TProperty)

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.

(Inherited from EntityTypeBuilder)

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

The PropertyAccessMode to use for properties of this entity type.

Returns
EntityTypeBuilder<TEntity> EntityTypeBuilder(Of TEntity)

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

Properties

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

The model that the entity type belongs to.

(Inherited from EntityTypeBuilder)

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

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

(Inherited from EntityTypeBuilder)

Metadata Metadata

The entity type being configured.

(Inherited from EntityTypeBuilder)