Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

PrimaryKeyAttribute Class

Definition

Namespace:
Microsoft.EntityFrameworkCore
Assembly:
Microsoft.EntityFrameworkCore.Abstractions.dll
Package:
Microsoft.EntityFrameworkCore.Abstractions v10.0.0
Package:
Microsoft.EntityFrameworkCore.Abstractions v7.0.0
Package:
Microsoft.EntityFrameworkCore.Abstractions v8.0.0
Package:
Microsoft.EntityFrameworkCore.Abstractions v9.0.0
Source:
PrimaryKeyAttribute.cs
Source:
PrimaryKeyAttribute.cs
Source:
PrimaryKeyAttribute.cs
Source:
PrimaryKeyAttribute.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Specifies a primary key for the entity type mapped to this CLR type.

[System.AttributeUsage(System.AttributeTargets.Class)]
[System.Runtime.CompilerServices.Nullable(0)]
public sealed class PrimaryKeyAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class PrimaryKeyAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
[<System.Runtime.CompilerServices.Nullable(0)>]
type PrimaryKeyAttribute = class
 inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type PrimaryKeyAttribute = class
 inherit Attribute
Public NotInheritable Class PrimaryKeyAttribute
Inherits Attribute
Inheritance
PrimaryKeyAttribute
Attributes

Remarks

This attribute can be used for both keys made up of a single property, and for composite keys made up of multiple properties. KeyAttribute can be used instead for single-property keys, in which case the behavior is identical. If both attributes are used, then this attribute takes precedence.

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

Constructors

Name Description
PrimaryKeyAttribute(String, String[])

Initializes a new instance of the PrimaryKeyAttribute class.

Properties

Name Description
PropertyNames

The properties which constitute the primary key, in order.

Applies to


Feedback

Was this page helpful?