The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

KeyAttribute Class

Indicates that a property or a field is a key.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.1.dll

Declaration

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class KeyAttribute : Attribute
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=True)>
Public NotInheritable Class KeyAttribute
    Inherits Attribute
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = true)]
public sealed class KeyAttribute : Attribute
<AttributeUsage(AttributeTargets.Field Or AttributeTargets.Property, Inherited:=True)>
Public NotInheritable Class KeyAttribute
    Inherits Attribute

Remarks

Apply this attribute to a property or a field to mark it as a key. The KeyAttribute.AutoGenerate property specifies whether the key is generated automatically.

Note

When a key is changed for a saved object, XPO considers this object as new and inserts a new record into the database. Key properties must not be changed once a persistent object is saved. An end-user must never be allowed to change an object's key property. We recommend that you define a key property as "read-only".


[Key(true), Persistent("CategoryID")]
int fCategoryID = -1;

[PersistentAlias("fCategoryID")]
public int CategoryID {
    get { return fCategoryID; }
}

Inheritance

Object
Attribute
KeyAttribute

Implements

See Also