EntityTypeBuilder Class

Definition

Provides a simple API for configuring an IMutableEntityType.

public class EntityTypeBuilder : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.IMutableModel>, Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder>
public class EntityTypeBuilder : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder>
public class EntityTypeBuilder : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Builders.IConventionEntityTypeBuilder>
type EntityTypeBuilder = class
    interface IInfrastructure<IMutableModel>
    interface IInfrastructure<InternalEntityTypeBuilder>
type EntityTypeBuilder = class
    interface IInfrastructure<InternalEntityTypeBuilder>
type EntityTypeBuilder = class
    interface IInfrastructure<IConventionEntityTypeBuilder>
Public Class EntityTypeBuilder
Implements IInfrastructure(Of IMutableModel), IInfrastructure(Of InternalEntityTypeBuilder)
Public Class EntityTypeBuilder
Implements IInfrastructure(Of InternalEntityTypeBuilder)
Public Class EntityTypeBuilder
Implements IInfrastructure(Of IConventionEntityTypeBuilder)
Inheritance
EntityTypeBuilder
Derived
Implements
IInfrastructure<IMutableModel> IInfrastructure<Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder> IInfrastructure<IConventionEntityTypeBuilder>

Remarks

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.

Constructors

EntityTypeBuilder(IMutableEntityType)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

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.

Properties

Metadata

The entity type being configured.

Methods

FindRelatedEntityType(String, String)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

FindRelatedEntityType(Type, String)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

HasAlternateKey(String[])

Creates an alternate key in the model for this entity type if one does not already exist over the specified properties. This will force the properties to be read-only. Use HasIndex to specify uniqueness in the model that does not force properties to be read-only.

HasAnnotation(String, Object)

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

HasBaseType(String)

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

HasBaseType(Type)

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

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.

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.

HasData(IEnumerable<Object>)

Configures this entity to have seed data. It is used to generate data motion migrations.

HasData(Object[])

Configures this entity to have seed data. It is used to generate data motion migrations.

HasDiscriminator()

Configures the discriminator property used to identify the entity type in the store.

HasDiscriminator(String, Type)

Configures the discriminator property used to identify the entity type in the store.

HasDiscriminator<TDiscriminator>(String)

Configures the discriminator property used to identify the entity type in the store.

HasIndex(String[])

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

HasIndex(String[], String)

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

HasKey(String[])

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

HasMany(String)

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

HasMany(String, String)

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

HasMany(Type, String)

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

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.

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.

HasNoDiscriminator()

Configures the entity type as having no discriminator property.

HasNoKey()

Configures the entity type to have no keys. It will only be usable for queries.

HasOne(String)

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

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.

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.

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.

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.

HasOneBuilder(MemberIdentity, EntityType)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

HasQueryFilter(LambdaExpression)

Specifies a LINQ predicate expression that will automatically be applied to any queries targeting this entity type.

HasTrigger(IMutableEntityType, String)

Configures a trigger for the the entity type.

Ignore(String)

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

IndexerProperty(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.

IndexerProperty<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.

Navigation(String)

Returns an object that can be used to configure an existing navigation property of the entity type. It is an error for the navigation property not to exist.

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.

OwnsMany(String, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsMany(String, String, Action<CollectionOwnershipBuilder>)

Configures a relationship where this entity type provides identity to the other type in the relationship.

OwnsMany(String, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsMany(String, Type, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsMany(String, Type, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsMany(Type, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsMany(Type, String, Action<CollectionOwnershipBuilder>)

Configures a relationship where this entity type provides identity to the other type in the relationship.

OwnsMany(Type, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(String, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(String, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(String, String, Action<ReferenceOwnershipBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

The target entity type for each ownership relationship is treated as a different entity type even if the navigation is of the same type. Configuration of the target entity type isn't applied to the target entity type of other ownership relationships.

Most operations on an owned entity require accessing it through the owner entity using the corresponding navigation.

OwnsOne(String, Type, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(String, Type, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(Type, String)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(Type, String, Action<OwnedNavigationBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

OwnsOne(Type, String, Action<ReferenceOwnershipBuilder>)

Configures a relationship where the target entity is owned by (or part of) this entity.

The target entity type for each ownership relationship is treated as a different entity type even if the navigation is of the same type. Configuration of the target entity type isn't applied to the target entity type of other ownership relationships.

Most operations on an owned entity require accessing it through the owner entity using the corresponding navigation.

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.

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.

Property<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.

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.

UsePropertyAccessMode(PropertyAccessMode)

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

Explicit Interface Implementations

IInfrastructure<IConventionEntityTypeBuilder>.Instance

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

IInfrastructure<IMutableModel>.Instance

The model that the entity type belongs to.

IInfrastructure<InternalEntityTypeBuilder>.Instance

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

Extension Methods

HasAnalyticalStoreTimeToLive(EntityTypeBuilder, Nullable<Int32>)

Configures the time to live for analytical store in seconds at container scope.

HasAutoscaleThroughput(EntityTypeBuilder, Nullable<Int32>)

Configures the autoscale provisioned throughput offering.

HasDefaultTimeToLive(EntityTypeBuilder, Nullable<Int32>)

Configures the default time to live in seconds at container scope.

HasManualThroughput(EntityTypeBuilder, Nullable<Int32>)

Configures the manual provisioned throughput offering.

HasPartitionKey(EntityTypeBuilder, String)

Configures the property that is used to store the partition key.

ToContainer(EntityTypeBuilder, String)

Configures the container that the entity type maps to when targeting Azure Cosmos.

UseETagConcurrency(EntityTypeBuilder)

Configures this entity to use CosmosDb etag concurrency checks.

GetInfrastructure<T>(IInfrastructure<T>)

Gets the value from a property that is being hidden using IInfrastructure<T>.

This method is typically used by database providers (and other extensions). It is generally not used in application code.

ToInMemoryQuery(EntityTypeBuilder, LambdaExpression)

Configures a query used to provide data for an entity type.

DeleteUsingStoredProcedure(EntityTypeBuilder, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for deletes when targeting a relational database.

DeleteUsingStoredProcedure(EntityTypeBuilder, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for deletes when targeting a relational database.

DeleteUsingStoredProcedure(EntityTypeBuilder, String, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for deletes when targeting a relational database.

HasCheckConstraint(EntityTypeBuilder, String, String)
Obsolete.

Configures a database check constraint when targeting a relational database.

HasCheckConstraint(EntityTypeBuilder, String, String, Action<CheckConstraintBuilder>)
Obsolete.

Configures a database check constraint when targeting a relational database.

HasComment(EntityTypeBuilder, String)
Obsolete.

Configures a comment to be applied to the table

HasDiscriminator(EntityTypeBuilder)

Configures the discriminator column used to identify which entity type each row in a table represents when an inheritance hierarchy is mapped to a single table in a relational database.

HasDiscriminator(EntityTypeBuilder, String, Type)

Configures the discriminator column used to identify which entity type each row in a table represents when an inheritance hierarchy is mapped to a single table in a relational database.

HasDiscriminator<TDiscriminator>(EntityTypeBuilder, String)

Configures the discriminator column used to identify which entity type each row in a table represents when an inheritance hierarchy is mapped to a single table in a relational database.

InsertUsingStoredProcedure(EntityTypeBuilder, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for inserts when targeting a relational database.

InsertUsingStoredProcedure(EntityTypeBuilder, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for inserts when targeting a relational database.

InsertUsingStoredProcedure(EntityTypeBuilder, String, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for inserts when targeting a relational database.

SplitToTable(EntityTypeBuilder, String, Action<SplitTableBuilder>)

Configures some of the properties on this entity type to be mapped to a different table. The primary key properties are mapped to all tables, other properties must be explicitly mapped.

SplitToTable(EntityTypeBuilder, String, String, Action<SplitTableBuilder>)

Configures some of the properties on this entity type to be mapped to a different table. The primary key properties are mapped to all tables, other properties must be explicitly mapped.

SplitToView(EntityTypeBuilder, String, Action<SplitViewBuilder>)

Configures some of the properties on this entity type to be mapped to a different view. The primary key properties are mapped to all views, other properties must be explicitly mapped.

SplitToView(EntityTypeBuilder, String, String, Action<SplitViewBuilder>)

Configures some of the properties on this entity type to be mapped to a different view. The primary key properties are mapped to all views, other properties must be explicitly mapped.

ToFunction(EntityTypeBuilder, MethodInfo)

Configures the function that the entity type maps to when targeting a relational database.

ToFunction(EntityTypeBuilder, MethodInfo, Action<TableValuedFunctionBuilder>)

Configures the function that the entity type maps to when targeting a relational database.

ToFunction(EntityTypeBuilder, String)

Configures the function that the entity type maps to when targeting a relational database.

ToFunction(EntityTypeBuilder, String, Action<TableValuedFunctionBuilder>)

Configures the function that the entity type maps to when targeting a relational database.

ToSqlQuery(EntityTypeBuilder, String)

Configures a SQL string used to provide data for the entity type.

ToTable(EntityTypeBuilder, Action<TableBuilder>)

Configures the table that the entity type maps to when targeting a relational database.

ToTable(EntityTypeBuilder, String)

Configures the table that the entity type maps to when targeting a relational database.

ToTable(EntityTypeBuilder, String, Action<TableBuilder>)

Configures the table that the entity type maps to when targeting a relational database.

ToTable(EntityTypeBuilder, String, String)

Configures the table that the entity type maps to when targeting a relational database.

ToTable(EntityTypeBuilder, String, String, Action<TableBuilder>)

Configures the table that the entity type maps to when targeting a relational database.

ToView(EntityTypeBuilder, String)

Configures the view that the entity type maps to when targeting a relational database.

ToView(EntityTypeBuilder, String, Action<ViewBuilder>)

Configures the view that the entity type maps to when targeting a relational database.

ToView(EntityTypeBuilder, String, String)

Configures the view that the entity type maps to when targeting a relational database.

ToView(EntityTypeBuilder, String, String, Action<ViewBuilder>)

Configures the view that the entity type maps to when targeting a relational database.

UpdateUsingStoredProcedure(EntityTypeBuilder, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for updates when targeting a relational database.

UpdateUsingStoredProcedure(EntityTypeBuilder, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for updates when targeting a relational database.

UpdateUsingStoredProcedure(EntityTypeBuilder, String, String, Action<StoredProcedureBuilder>)

Configures the stored procedure that the entity type uses for updates when targeting a relational database.

UseTpcMappingStrategy(EntityTypeBuilder)

Configures TPC as the mapping strategy for the derived types. Each type will be mapped to a different database object. All properties will be mapped to columns on the corresponding object.

UseTphMappingStrategy(EntityTypeBuilder)

Configures TPH as the mapping strategy for the derived types. All types will be mapped to the same database object. This is the default mapping strategy.

UseTptMappingStrategy(EntityTypeBuilder)

Configures TPT as the mapping strategy for the derived types. Each type will be mapped to a different database object. Only the declared properties will be mapped to columns on the corresponding object.

ForSqliteToTable(EntityTypeBuilder, String)

Configures the table that the entity maps to when targeting SQLite.

ForSqlServerIsMemoryOptimized(EntityTypeBuilder, Boolean)
Obsolete.

Configures the table that the entity maps to when targeting SQL Server as memory-optimized.

ForSqlServerToTable(EntityTypeBuilder, String)

Configures the table that the entity maps to when targeting SQL Server.

ForSqlServerToTable(EntityTypeBuilder, String, String)

Configures the table that the entity maps to when targeting SQL Server.

IsMemoryOptimized(EntityTypeBuilder, Boolean)
Obsolete.

Configures the table that the entity maps to when targeting SQL Server as memory-optimized.

Applies to