Back to Devexpress

KeyAttribute Class

xpo-devexpress-dot-xpo-a595d493.md

latest2.0 KB
Original Source

KeyAttribute Class

Indicates that a property or a field is a key.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class KeyAttribute :
    Attribute
vb
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, 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.

You can change key property values for new unsaved objects only. If you change a key property for a saved object, the identity map may not function correctly. Define a key property as “read-only” whenever possible:

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

[PersistentAlias(nameof(fCategoryID))]
public int CategoryID {
    get { return fCategoryID; }
}
vb
<Key(True), Persistent("CategoryID")> _
Private fCategoryID As Integer = -1

<PersistentAlias(NameOf(fCategoryID))> _
Public ReadOnly Property CategoryID() As Integer
    Get
        Return fCategoryID
    End Get
End Property

Inheritance

Object Attribute KeyAttribute

See Also

KeyAttribute Members

Built-In Attributes

DevExpress.Xpo Namespace