Table of Contents

Class RelationalForeignKeyExtensions

Namespace
Microsoft.EntityFrameworkCore
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

Foreign key extension methods for relational database metadata.

public static class RelationalForeignKeyExtensions
Inheritance
RelationalForeignKeyExtensions
Inherited Members

Remarks

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

Methods

FindSharedObjectRootForeignKey(IConventionForeignKey, in StoreObjectIdentifier)

Finds the first Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey 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.

public static IConventionForeignKey? FindSharedObjectRootForeignKey(this IConventionForeignKey foreignKey, in StoreObjectIdentifier storeObject)

Parameters

foreignKey IConventionForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

Returns

IConventionForeignKey

The foreign key if found, or null if none was found.

FindSharedObjectRootForeignKey(IForeignKey, in StoreObjectIdentifier)

Finds the first Microsoft.EntityFrameworkCore.Metadata.IConventionForeignKey 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.

public static IForeignKey? FindSharedObjectRootForeignKey(this IForeignKey foreignKey, in StoreObjectIdentifier storeObject)

Parameters

foreignKey IForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

Returns

IForeignKey

The foreign key if found, or null if none was found.

FindSharedObjectRootForeignKey(IMutableForeignKey, in StoreObjectIdentifier)

Finds the first Microsoft.EntityFrameworkCore.Metadata.IMutableForeignKey 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.

public static IMutableForeignKey? FindSharedObjectRootForeignKey(this IMutableForeignKey foreignKey, in StoreObjectIdentifier storeObject)

Parameters

foreignKey IMutableForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

Returns

IMutableForeignKey

The foreign key if found, or null if none was found.

FindSharedObjectRootForeignKey(IReadOnlyForeignKey, in StoreObjectIdentifier)

Finds the first Microsoft.EntityFrameworkCore.Metadata.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.

public static IReadOnlyForeignKey? FindSharedObjectRootForeignKey(this IReadOnlyForeignKey foreignKey, in StoreObjectIdentifier storeObject)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

Returns

IReadOnlyForeignKey

The foreign key if found, or null if none was found.

GetConstraintName(IReadOnlyForeignKey)

Returns the foreign key constraint name.

public static string? GetConstraintName(this IReadOnlyForeignKey foreignKey)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

Returns

string

The foreign key constraint name.

GetConstraintName(IReadOnlyForeignKey, in StoreObjectIdentifier, in StoreObjectIdentifier)

Returns the foreign key constraint name.

public static string? GetConstraintName(this IReadOnlyForeignKey foreignKey, in StoreObjectIdentifier storeObject, in StoreObjectIdentifier principalStoreObject)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

principalStoreObject StoreObjectIdentifier

The identifier of the principal store object.

Returns

string

The foreign key constraint name.

GetConstraintNameConfigurationSource(IConventionForeignKey)

Gets the Microsoft.EntityFrameworkCore.Metadata.ConfigurationSource for the constraint name.

public static ConfigurationSource? GetConstraintNameConfigurationSource(this IConventionForeignKey foreignKey)

Parameters

foreignKey IConventionForeignKey

The foreign key.

Returns

ConfigurationSource?

The Microsoft.EntityFrameworkCore.Metadata.ConfigurationSource for the constraint name.

GetDefaultName(IReadOnlyForeignKey)

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

public static string? GetDefaultName(this IReadOnlyForeignKey foreignKey)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

Returns

string

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

GetDefaultName(IReadOnlyForeignKey, in StoreObjectIdentifier, in StoreObjectIdentifier)

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

public static string? GetDefaultName(this IReadOnlyForeignKey foreignKey, in StoreObjectIdentifier storeObject, in StoreObjectIdentifier principalStoreObject)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the containing store object.

principalStoreObject StoreObjectIdentifier

The identifier of the principal store object.

Returns

string

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

GetMappedConstraints(IForeignKey)

Gets the foreign key constraints to which the foreign key is mapped.

public static IEnumerable<IForeignKeyConstraint> GetMappedConstraints(this IForeignKey foreignKey)

Parameters

foreignKey IForeignKey

The foreign key.

Returns

IEnumerable<IForeignKeyConstraint>

The foreign key constraints to which the foreign key is mapped.

IsRowInternal(IReadOnlyForeignKey, StoreObjectIdentifier)

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

public static bool IsRowInternal(this IReadOnlyForeignKey foreignKey, StoreObjectIdentifier storeObject)

Parameters

foreignKey IReadOnlyForeignKey

The foreign key.

storeObject StoreObjectIdentifier

The identifier of the store object.

Returns

bool

SetConstraintName(IConventionForeignKey, string?, bool)

Sets the foreign key constraint name.

public static string? SetConstraintName(this IConventionForeignKey foreignKey, string? value, bool fromDataAnnotation = false)

Parameters

foreignKey IConventionForeignKey

The foreign key.

value string

The value to set.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

string

The configured name.

SetConstraintName(IMutableForeignKey, string?)

Sets the foreign key constraint name.

public static void SetConstraintName(this IMutableForeignKey foreignKey, string? value)

Parameters

foreignKey IMutableForeignKey

The foreign key.

value string

The value to set.