Langue

IReadOnlyForeignKey Interface

Definition

Represents a relationship where a foreign key composed of properties on the dependent entity type references a corresponding primary or alternate key on the principal entity type.

public interface IReadOnlyForeignKey : Microsoft.EntityFrameworkCore.Infrastructure.IReadOnlyAnnotatable
type IReadOnlyForeignKey = interface
    interface IReadOnlyAnnotatable
Public Interface IReadOnlyForeignKey
Implements IReadOnlyAnnotatable
Derived
Implements

Remarks

See Modeling entity types and relationships for more information and examples.

Properties

Name Description
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).

DeleteBehavior

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

DependentToPrincipal

Gets the navigation property on the dependent entity type that points to the principal entity.

IsConstrained

Gets a value indicating whether the relationship is constrained, that is, backed by a guarantee (such as a database foreign key constraint) that a matching principal key exists for every set foreign key value. When false, no database foreign key constraint is created and queries treat the relationship as optional even when the foreign key properties are non-nullable — the principal is loaded with a left join and is never assumed to exist. This does not affect change tracking: a required (IsRequired) relationship still cascades or produces a conceptual null when severed, regardless of this value.

IsOwnership

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

IsRequired

Gets a value indicating whether the principal entity is required. If true, the dependent entity must always be assigned to a valid principal entity.

IsRequiredDependent

Gets a value indicating whether the dependent entity is required. If true, the principal entity must always have a valid dependent entity assigned.

IsUnique

Gets a value indicating whether the values assigned to the foreign key properties are unique.

Item[String]

Gets the value of the annotation with the given name, returning null if it does not exist.

(Inherited from IReadOnlyAnnotatable)
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).

PrincipalKey

Gets the primary or alternate key that the relationship targets.

PrincipalToDependent

Gets the navigation property on the principal entity type that points to the dependent entity.

Properties

Gets the foreign key properties in the dependent entity.

Methods

Name Description
AnnotationsToDebugString(Int32)

Gets the debug string for all annotations declared on the object.

(Inherited from IReadOnlyAnnotatable)
FindAnnotation(String)

Gets the annotation with the given name, returning null if it does not exist.

(Inherited from IReadOnlyAnnotatable)
GetAnnotation(String)

Gets the annotation with the given name, throwing if it does not exist.

(Inherited from IReadOnlyAnnotatable)
GetAnnotations()

Gets all annotations on the current object.

(Inherited from IReadOnlyAnnotatable)
GetNavigation(Boolean)

Returns a navigation associated with this foreign key.

GetReferencingSkipNavigations()

Gets the skip navigations using this foreign key.

GetRelatedEntityType(IReadOnlyEntityType)

Gets the entity type related to the given one.

IsBaseLinking()

Returns a value indicating whether the foreign key is defined on the primary key and pointing to the same primary key.

IsEffectivelyRequired()

Returns a value indicating whether a set value for this foreign key is guaranteed to reference an existing principal — that is, the relationship is both required (IsRequired) and constrained (IsConstrained). Query consults this to decide whether a dependent-to-principal navigation can be expanded with an inner join (and whether such a join can be pruned); an unconstrained relationship is always treated as optional even when its foreign key properties are non-nullable.

ToDebugString(MetadataDebugStringOptions, Int32)

Creates a human-readable representation of the given metadata.

Warning: Do not rely on the format of the returned string. It is designed for debugging only and may change arbitrarily between releases.

Extension Methods

Name Description
FindSharedObjectRootForeignKey(IReadOnlyForeignKey, StoreObjectIdentifier)

Finds the first IForeignKey that is mapped to the same constraint in a shared table-like object.

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

GetConstraintName(IReadOnlyForeignKey, StoreObjectIdentifier, StoreObjectIdentifier)

Returns the foreign key constraint name.

GetConstraintName(IReadOnlyForeignKey)

Returns the foreign key constraint name.

GetDefaultName(IReadOnlyForeignKey, StoreObjectIdentifier, StoreObjectIdentifier)

Returns the default constraint name that would be used for this foreign key.

GetDefaultName(IReadOnlyForeignKey)

Returns the default constraint name that would be used for this foreign key.

IsExcludedFromMigrations(IReadOnlyForeignKey)

Returns a value indicating whether the foreign key constraint is excluded from migrations.

IsRowInternal(IReadOnlyForeignKey, StoreObjectIdentifier)

Returns a value indicating whether this foreign key is between two entity types sharing the same table-like store object.

Applies to