KeyAttribute Class
Indicates that a property or a field is a key.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v19.2.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
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:
[Key(true), Persistent("CategoryID")]
int fCategoryID = -1;
[PersistentAlias(nameof(fCategoryID))]
public int CategoryID {
get { return fCategoryID; }
}
<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
See Also