Delen via


PrimaryKeyAttribute Class

Definition

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

[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class PrimaryKeyAttribute : 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

PrimaryKeyAttribute(String, String[])

Initializes a new instance of the PrimaryKeyAttribute class.

Properties

PropertyNames

The properties which constitute the primary key, in order.

Applies to