Table of Contents

Interface IKey

Namespace
Microsoft.EntityFrameworkCore.Metadata
Assembly
Microsoft.EntityFrameworkCore.dll

Represents a primary or alternate key on an entity type.

public interface IKey : IReadOnlyKey, IAnnotatable, IReadOnlyAnnotatable
Inherited Members
Extension Methods

Remarks

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

Properties

DeclaringEntityType

Gets the entity type the key is defined on. This may be different from the type that Properties are defined on when the key is defined a derived type in an inheritance hierarchy (since the properties may be defined on a base type).

IEntityType DeclaringEntityType { get; }

Property Value

IEntityType

Properties

Gets the properties that make up the key.

IReadOnlyList<IProperty> Properties { get; }

Property Value

IReadOnlyList<IProperty>

Methods

GetKeyType()

Returns the type of the key property for simple keys, or an object array for composite keys.

Type GetKeyType()

Returns

Type

The key type.

GetPrincipalKeyValueFactory()

Gets a factory for key values based on the key values taken from various forms of entity data.

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

IPrincipalKeyValueFactory GetPrincipalKeyValueFactory()

Returns

IPrincipalKeyValueFactory

The factory.

GetPrincipalKeyValueFactory<TKey>()

Gets a factory for key values based on the key values taken from various forms of entity data.

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

IPrincipalKeyValueFactory<TKey> GetPrincipalKeyValueFactory<TKey>() where TKey : notnull

Returns

IPrincipalKeyValueFactory<TKey>

The factory.

Type Parameters

TKey

The type of the key instance.

GetReferencingForeignKeys()

Gets all foreign keys that target a given primary or alternate key.

IEnumerable<IForeignKey> GetReferencingForeignKeys()

Returns

IEnumerable<IForeignKey>

The foreign keys that reference the given key.