Class ReferenceReferenceBuilder<TEntity, TRelatedEntity>
- Namespace
- Microsoft.EntityFrameworkCore.Metadata.Builders
- Assembly
- Microsoft.EntityFrameworkCore.dll
Provides a simple API for configuring a one-to-one relationship.
public class ReferenceReferenceBuilder<TEntity, TRelatedEntity> : ReferenceReferenceBuilder, IInfrastructure<IConventionForeignKeyBuilder> where TEntity : class where TRelatedEntity : class
Type Parameters
TEntity
TRelatedEntity
- Inheritance
-
ReferenceReferenceBuilder<TEntity, TRelatedEntity>
- Implements
- Inherited Members
- Extension Methods
Remarks
See Modeling entity types and relationships for more information and examples.
Constructors
ReferenceReferenceBuilder(IMutableEntityType, IMutableEntityType, IMutableForeignKey)
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.
[EntityFrameworkInternal]
public ReferenceReferenceBuilder(IMutableEntityType declaringEntityType, IMutableEntityType relatedEntityType, IMutableForeignKey foreignKey)
Parameters
declaringEntityType
IMutableEntityTyperelatedEntityType
IMutableEntityTypeforeignKey
IMutableForeignKey
ReferenceReferenceBuilder(InternalForeignKeyBuilder, ReferenceReferenceBuilder, bool, bool, bool, bool)
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.
[EntityFrameworkInternal]
protected ReferenceReferenceBuilder(InternalForeignKeyBuilder builder, ReferenceReferenceBuilder oldBuilder, bool inverted = false, bool foreignKeySet = false, bool principalKeySet = false, bool requiredSet = false)
Parameters
builder
InternalForeignKeyBuilderoldBuilder
ReferenceReferenceBuilderinverted
boolforeignKeySet
boolprincipalKeySet
boolrequiredSet
bool
Methods
HasAnnotation(string, object?)
Adds or updates an annotation on the relationship. If an annotation with the key specified in
annotation
already exists its value will be updated.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasAnnotation(string annotation, object? value)
Parameters
annotation
stringThe key of the annotation to be added or updated.
value
objectThe value to be stored in the annotation.
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
HasForeignKey(string, params string[])
Configures the property(s) to use as the foreign key for this relationship.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasForeignKey(string dependentEntityTypeName, params string[] foreignKeyPropertyNames)
Parameters
dependentEntityTypeName
stringThe name of entity type that is the dependent in this relationship (the type that has the foreign key properties).
foreignKeyPropertyNames
string[]The name(s) of the foreign key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Remarks
If the specified property name(s) do not exist on the entity type then a new shadow state property(s) will be added to serve as the foreign key. 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.
If HasPrincipalKey(string, params string[]) is not specified, then an attempt will be made to match the data type and order of foreign key properties against the primary key of the principal entity type. If they do not match, new shadow state properties that form a unique index will be added to the principal entity type to serve as the reference key.
HasForeignKey(Type, params string[])
Configures the property(s) to use as the foreign key for this relationship.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasForeignKey(Type dependentEntityType, params string[] foreignKeyPropertyNames)
Parameters
dependentEntityType
TypeThe entity type that is the dependent in this relationship (the type that has the foreign key properties).
foreignKeyPropertyNames
string[]The name(s) of the foreign key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Remarks
If the specified property name(s) do not exist on the entity type then a new shadow state property(s) will be added to serve as the foreign key. 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.
If HasPrincipalKey(Type, params string[]) is not specified, then an attempt will be made to match the data type and order of foreign key properties against the primary key of the principal entity type. If they do not match, new shadow state properties that form a unique index will be added to the principal entity type to serve as the reference key.
HasForeignKey<TDependentEntity>(Expression<Func<TDependentEntity, object?>>)
Configures the property(s) to use as the foreign key for this relationship.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasForeignKey<TDependentEntity>(Expression<Func<TDependentEntity, object?>> foreignKeyExpression) where TDependentEntity : class
Parameters
foreignKeyExpression
Expression<Func<TDependentEntity, object>>A lambda expression representing the foreign key property(s) (
t => t.Id1
).If the foreign key is made up of multiple properties then specify an anonymous type including the properties (
t => new { t.Id1, t.Id2 }
). The order specified should match the order of corresponding keys in HasPrincipalKey<TPrincipalEntity>(Expression<Func<TPrincipalEntity, object?>>).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Type Parameters
TDependentEntity
The entity type that is the dependent in this relationship. That is, the type that has the foreign key properties.
Remarks
If the specified property name(s) do not exist on the entity type then a new shadow state property(s) will be added to serve as the foreign key. 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.
If HasPrincipalKey<TPrincipalEntity>(Expression<Func<TPrincipalEntity, object?>>) is not specified, then an attempt will be made to match the data type and order of foreign key properties against the primary key of the principal entity type. If they do not match, new shadow state properties that form a unique index will be added to the principal entity type to serve as the reference key.
HasForeignKey<TDependentEntity>(params string[])
Configures the property(s) to use as the foreign key for this relationship.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasForeignKey<TDependentEntity>(params string[] foreignKeyPropertyNames) where TDependentEntity : class
Parameters
foreignKeyPropertyNames
string[]The name(s) of the foreign key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Type Parameters
TDependentEntity
The entity type that is the dependent in this relationship (the type that has the foreign key properties).
Remarks
If the specified property name(s) do not exist on the entity type then a new shadow state property(s) will be added to serve as the foreign key. 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.
If HasPrincipalKey<TPrincipalEntity>(params string[]) is not specified, then an attempt will be made to match the data type and order of foreign key properties against the primary key of the principal entity type. If they do not match, new shadow state properties that form a unique index will be added to the principal entity type to serve as the referenced key.
HasPrincipalKey(string, params string[])
Configures the unique property(s) that this relationship targets. Typically you would only call this method if you want to use a property(s) other than the primary key as the principal property(s). If the specified property(s) is not already a unique constraint (or the primary key) then a new unique constraint will be introduced.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasPrincipalKey(string principalEntityTypeName, params string[] keyPropertyNames)
Parameters
principalEntityTypeName
stringThe name of entity type that is the principal in this relationship (the type that has the reference key properties).
keyPropertyNames
string[]The name(s) of the reference key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
HasPrincipalKey(Type, params string[])
Configures the unique property(s) that this relationship targets. Typically you would only call this method if you want to use a property(s) other than the primary key as the principal property(s). If the specified property(s) is not already a unique constraint (or the primary key) then a new unique constraint will be introduced.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasPrincipalKey(Type principalEntityType, params string[] keyPropertyNames)
Parameters
principalEntityType
TypeThe entity type that is the principal in this relationship (the type that has the reference key properties).
keyPropertyNames
string[]The name(s) of the reference key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
HasPrincipalKey<TPrincipalEntity>(Expression<Func<TPrincipalEntity, object?>>)
Configures the unique property(s) that this relationship targets. Typically you would only call this method if you want to use a property(s) other than the primary key as the principal property(s). If the specified property(s) is not already a unique constraint (or the primary key) then a new unique constraint will be introduced.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasPrincipalKey<TPrincipalEntity>(Expression<Func<TPrincipalEntity, object?>> keyExpression) where TPrincipalEntity : class
Parameters
keyExpression
Expression<Func<TPrincipalEntity, object>>A lambda expression representing the reference key property(s) (
t => t.Id
).If the principal key is made up of multiple properties then specify an anonymous type including the properties (
t => new { t.Id1, t.Id2 }
). The order specified should match the order of corresponding properties in HasForeignKey<TDependentEntity>(Expression<Func<TDependentEntity, object?>>).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Type Parameters
TPrincipalEntity
The entity type that is the principal in this relationship. That is, the type that has the reference key properties.
Remarks
If multiple principal key properties are specified, the order of principal key properties should match the order that the primary key or unique constraint properties were configured on the principal entity type.
HasPrincipalKey<TPrincipalEntity>(params string[])
Configures the unique property(s) that this relationship targets. Typically you would only call this method if you want to use a property(s) other than the primary key as the principal property(s). If the specified property(s) is not already a unique constraint (or the primary key) then a new unique constraint will be introduced.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> HasPrincipalKey<TPrincipalEntity>(params string[] keyPropertyNames) where TPrincipalEntity : class
Parameters
keyPropertyNames
string[]The name(s) of the reference key property(s).
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
Type Parameters
TPrincipalEntity
The entity type that is the principal in this relationship (the type that has the reference key properties).
IsRequired(bool)
Configures whether this is a required relationship (i.e. whether the foreign key property(s) can be assigned null).
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> IsRequired(bool required = true)
Parameters
required
boolA value indicating whether this is a required relationship.
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.
OnDelete(DeleteBehavior)
Configures the operation applied to dependent entities in the relationship when the principal is deleted or the relationship is severed.
public virtual ReferenceReferenceBuilder<TEntity, TRelatedEntity> OnDelete(DeleteBehavior deleteBehavior)
Parameters
deleteBehavior
DeleteBehaviorThe action to perform.
Returns
- ReferenceReferenceBuilder<TEntity, TRelatedEntity>
The same builder instance so that multiple configuration calls can be chained.