Interface IConventionForeignKey
- Namespace
- Microsoft.EntityFrameworkCore.Metadata
- Assembly
- Microsoft.EntityFrameworkCore.dll
Represents a relationship where a foreign key property(s) in a dependent entity type reference a corresponding primary or alternate key in a principal entity type.
public interface IConventionForeignKey : IReadOnlyForeignKey, IConventionAnnotatable, IReadOnlyAnnotatable
- Inherited Members
- Extension Methods
Remarks
This interface is used during model creation and allows the metadata to be modified. Once the model is built, IForeignKey represents a read-only view of the same metadata.
See Model building conventions for more information and examples.
Properties
Builder
Gets the builder that can be used to configure this foreign key.
IConventionForeignKeyBuilder Builder { get; }
Property Value
Exceptions
- InvalidOperationException
If the foreign key has been removed from the model.
DeclaringEntityType
Gets the dependent entity type. This may be different from the type that Properties are defined on when the relationship is defined a derived type in an inheritance hierarchy (since the properties may be defined on a base type).
IConventionEntityType DeclaringEntityType { get; }
Property Value
DependentToPrincipal
Gets the navigation property on the dependent entity type that points to the principal entity.
IConventionNavigation? DependentToPrincipal { get; }
Property Value
PrincipalEntityType
Gets the principal entity type that this relationship targets. This may be different from the type that PrincipalKey is defined on when the relationship targets a derived type in an inheritance hierarchy (since the key is defined on the base type of the hierarchy).
IConventionEntityType PrincipalEntityType { get; }
Property Value
PrincipalKey
Gets the primary or alternate key that the relationship targets.
IConventionKey PrincipalKey { get; }
Property Value
PrincipalToDependent
Gets the navigation property on the principal entity type that points to the dependent entity.
IConventionNavigation? PrincipalToDependent { get; }
Property Value
Properties
Gets the foreign key properties in the dependent entity.
IReadOnlyList<IConventionProperty> Properties { get; }
Property Value
Methods
GetConfigurationSource()
Returns the configuration source for this property.
ConfigurationSource GetConfigurationSource()
Returns
- ConfigurationSource
The configuration source.
GetDeleteBehaviorConfigurationSource()
Returns the configuration source for DeleteBehavior.
ConfigurationSource? GetDeleteBehaviorConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for DeleteBehavior.
GetDependentToPrincipalConfigurationSource()
Returns the configuration source for DependentToPrincipal.
ConfigurationSource? GetDependentToPrincipalConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for DependentToPrincipal.
GetIsOwnershipConfigurationSource()
Returns the configuration source for IsOwnership.
ConfigurationSource? GetIsOwnershipConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for IsOwnership.
GetIsRequiredConfigurationSource()
Returns the configuration source for IsRequired.
ConfigurationSource? GetIsRequiredConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for IsRequired.
GetIsRequiredDependentConfigurationSource()
Returns the configuration source for IsRequiredDependent.
ConfigurationSource? GetIsRequiredDependentConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for IsRequiredDependent.
GetIsUniqueConfigurationSource()
Returns the configuration source for IsUnique.
ConfigurationSource? GetIsUniqueConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for IsUnique.
GetNavigation(bool)
Returns a navigation associated with this foreign key.
IConventionNavigation? GetNavigation(bool pointsToPrincipal)
Parameters
pointsToPrincipal
boolA value indicating whether the navigation is on the dependent type pointing to the principal type.
Returns
- IConventionNavigation
A navigation associated with this foreign key or null.
GetPrincipalEndConfigurationSource()
Returns the configuration source for PrincipalEntityType.
ConfigurationSource? GetPrincipalEndConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for PrincipalEntityType.
GetPrincipalKeyConfigurationSource()
Returns the configuration source for PrincipalKey.
ConfigurationSource? GetPrincipalKeyConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for PrincipalKey.
GetPrincipalToDependentConfigurationSource()
Returns the configuration source for PrincipalToDependent.
ConfigurationSource? GetPrincipalToDependentConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for PrincipalToDependent.
GetPropertiesConfigurationSource()
Returns the configuration source for Properties.
ConfigurationSource? GetPropertiesConfigurationSource()
Returns
- ConfigurationSource?
The configuration source for Properties.
GetReferencingSkipNavigations()
Gets all skip navigations using this foreign key.
IEnumerable<IConventionSkipNavigation> GetReferencingSkipNavigations()
Returns
- IEnumerable<IConventionSkipNavigation>
The skip navigations using this foreign key.
GetRelatedEntityType(IReadOnlyEntityType)
Gets the entity type related to the given one.
IConventionEntityType GetRelatedEntityType(IReadOnlyEntityType entityType)
Parameters
entityType
IReadOnlyEntityTypeOne of the entity types related by the foreign key.
Returns
- IConventionEntityType
The entity type related to the given one.
SetDeleteBehavior(DeleteBehavior?, bool)
Sets a value indicating how a delete operation is applied to dependent entities in the relationship when the principal is deleted or the relationship is severed.
DeleteBehavior? SetDeleteBehavior(DeleteBehavior? deleteBehavior, bool fromDataAnnotation = false)
Parameters
deleteBehavior
DeleteBehavior?A value indicating how a delete operation is applied to dependent entities in the relationship when the principal is deleted or the relationship is severed.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- DeleteBehavior?
The configured behavior.
SetDependentToPrincipal(MemberInfo?, bool)
Sets the navigation property on the dependent entity type that points to the principal entity.
IConventionNavigation? SetDependentToPrincipal(MemberInfo? property, bool fromDataAnnotation = false)
Parameters
property
MemberInfoThe navigation property on the dependent type. Passing null will result in there being no navigation property defined.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionNavigation
The newly created navigation property.
SetDependentToPrincipal(string?, bool)
Sets the navigation property on the dependent entity type that points to the principal entity.
IConventionNavigation? SetDependentToPrincipal(string? name, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the navigation property on the dependent type. Passing null will result in there being no navigation property defined.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionNavigation
The newly created navigation property.
SetIsOwnership(bool?, bool)
Sets a value indicating whether this relationship defines an ownership. If true, the dependent entity must always be accessed via the navigation from the principal entity.
bool? SetIsOwnership(bool? ownership, bool fromDataAnnotation = false)
Parameters
ownership
bool?A value indicating whether this relationship defines an ownership.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool?
The configured ownership.
SetIsRequired(bool?, bool)
Sets a value indicating whether the principal entity is required. If true, the dependent entity must always be assigned to a valid principal entity.
bool? SetIsRequired(bool? required, bool fromDataAnnotation = false)
Parameters
required
bool?A value indicating whether the principal entity is required.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool?
The configured requiredness.
SetIsRequiredDependent(bool?, bool)
Sets a value indicating whether the dependent entity is required. If true, the principal entity must always have a valid dependent entity assigned.
bool? SetIsRequiredDependent(bool? required, bool fromDataAnnotation = false)
Parameters
required
bool?A value indicating whether the dependent entity is required.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool?
The configured requiredness.
SetIsUnique(bool?, bool)
Sets a value indicating whether the values assigned to the foreign key properties are unique.
bool? SetIsUnique(bool? unique, bool fromDataAnnotation = false)
Parameters
unique
bool?A value indicating whether the values assigned to the foreign key properties are unique.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- bool?
The configured uniqueness.
SetPrincipalToDependent(MemberInfo?, bool)
Sets the navigation property on the principal entity type that points to the dependent entity.
IConventionNavigation? SetPrincipalToDependent(MemberInfo? property, bool fromDataAnnotation = false)
Parameters
property
MemberInfoThe name of the navigation property on the principal type. Passing null will result in there being no navigation property defined.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionNavigation
The newly created navigation property.
SetPrincipalToDependent(string?, bool)
Sets the navigation property on the principal entity type that points to the dependent entity.
IConventionNavigation? SetPrincipalToDependent(string? name, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the navigation property on the principal type. Passing null will result in there being no navigation property defined.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionNavigation
The newly created navigation property.
SetProperties(IReadOnlyList<IConventionProperty>, IConventionKey, bool)
Sets the foreign key properties and that target principal key.
IReadOnlyList<IConventionProperty> SetProperties(IReadOnlyList<IConventionProperty> properties, IConventionKey principalKey, bool fromDataAnnotation = false)
Parameters
properties
IReadOnlyList<IConventionProperty>Foreign key properties in the dependent entity.
principalKey
IConventionKeyThe primary or alternate key to target.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IReadOnlyList<IConventionProperty>
The configured foreign key properties.