Table of Contents

Interface IMutableForeignKey

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 IMutableForeignKey : IReadOnlyForeignKey, IMutableAnnotatable, 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 Modeling entity types and relationships for more information and examples.

Properties

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

IMutableEntityType DeclaringEntityType { get; }

Property Value

IMutableEntityType

DeleteBehavior

Gets or 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 DeleteBehavior { get; set; }

Property Value

DeleteBehavior

DependentToPrincipal

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

IMutableNavigation? DependentToPrincipal { get; }

Property Value

IMutableNavigation

IsOwnership

Gets or sets a value indicating whether this relationship defines ownership. If true, the dependent entity must always be accessed via the navigation from the principal entity.

bool IsOwnership { get; set; }

Property Value

bool

IsRequired

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 IsRequired { get; set; }

Property Value

bool

IsRequiredDependent

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

bool IsRequiredDependent { get; set; }

Property Value

bool

IsUnique

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

bool IsUnique { get; set; }

Property Value

bool

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

IMutableEntityType PrincipalEntityType { get; }

Property Value

IMutableEntityType

PrincipalKey

Gets the primary or alternate key that the relationship targets.

IMutableKey PrincipalKey { get; }

Property Value

IMutableKey

PrincipalToDependent

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

IMutableNavigation? PrincipalToDependent { get; }

Property Value

IMutableNavigation

Properties

Gets the foreign key properties in the dependent entity.

IReadOnlyList<IMutableProperty> Properties { get; }

Property Value

IReadOnlyList<IMutableProperty>

Methods

GetNavigation(bool)

Returns a navigation associated with this foreign key.

IMutableNavigation? GetNavigation(bool pointsToPrincipal)

Parameters

pointsToPrincipal bool

A value indicating whether the navigation is on the dependent type pointing to the principal type.

Returns

IMutableNavigation

A navigation associated with this foreign key or null.

GetReferencingSkipNavigations()

Gets all skip navigations using this foreign key.

IEnumerable<IMutableSkipNavigation> GetReferencingSkipNavigations()

Returns

IEnumerable<IMutableSkipNavigation>

The skip navigations using this foreign key.

GetRelatedEntityType(IReadOnlyEntityType)

Gets the entity type related to the given one.

IMutableEntityType GetRelatedEntityType(IReadOnlyEntityType entityType)

Parameters

entityType IReadOnlyEntityType

One of the entity types related by the foreign key.

Returns

IMutableEntityType

The entity type related to the given one.

SetDependentToPrincipal(MemberInfo?)

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

IMutableNavigation? SetDependentToPrincipal(MemberInfo? property)

Parameters

property MemberInfo

The navigation property on the dependent type. Passing null will result in there being no navigation property defined.

Returns

IMutableNavigation

The newly set navigation property.

SetDependentToPrincipal(string?)

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

IMutableNavigation? SetDependentToPrincipal(string? name)

Parameters

name string

The name of the navigation property on the dependent type. Passing null will result in there being no navigation property defined.

Returns

IMutableNavigation

The newly set navigation property.

SetPrincipalToDependent(MemberInfo?)

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

IMutableNavigation? SetPrincipalToDependent(MemberInfo? property)

Parameters

property MemberInfo

The name of the navigation property on the principal type. Passing null will result in there being no navigation property defined.

Returns

IMutableNavigation

The newly set navigation property.

SetPrincipalToDependent(string?)

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

IMutableNavigation? SetPrincipalToDependent(string? name)

Parameters

name string

The name of the navigation property on the principal type. Passing null will result in there being no navigation property defined.

Returns

IMutableNavigation

The newly set navigation property.

SetProperties(IReadOnlyList<IMutableProperty>, IMutableKey)

Sets the foreign key properties and that target principal key.

void SetProperties(IReadOnlyList<IMutableProperty> properties, IMutableKey principalKey)

Parameters

properties IReadOnlyList<IMutableProperty>

Foreign key properties in the dependent entity.

principalKey IMutableKey

The primary or alternate key to target.