Back to Devexpress

KeyAttribute.AutoGenerate Property

xpo-devexpress-dot-xpo-dot-keyattribute.md

latest2.5 KB
Original Source

KeyAttribute.AutoGenerate Property

Gets or sets whether the key is generated automatically.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public bool AutoGenerate { get; set; }
vb
Public Property AutoGenerate As Boolean

Property Value

TypeDescription
Boolean

true to generate the key automatically; otherwise, false.

|

Remarks

Automatic key generation is supported for Int32, Int64 and Guid type keys. Guid key values are always generated on the client side, while Int32 and Int64 key values are generated using database facilities. Based on the database type, automatic key generation is implemented using identity/autonumber/auto-increment fields or sequences. If a database doesn’t provide any of these facilities, key values are generated by XPO.

Decorate a key property with the KeyAttribute and pass the attribute’s parameter to specify this property as shown below.

csharp
public class Customer : XPBaseObject {
    int oid;
    [Key(true)]
    public int Oid { 
        get { return oid; } 
        set { SetPropertyValue(nameof(Oid), ref oid, value); } 
    }
    // ...
}
vb
Public Class Customer
    Inherits XPBaseObject
    Private fOid As Integer
    <Key(True)>
    Public Property Oid() As Integer
        Get
            Return fOid
        End Get
        Set(ByVal value As Integer)
            SetPropertyValue(NameOf(Oid), fOid, value)
        End Set
    End Property
    ' ...
End Class

See Also

KeyAttribute Class

KeyAttribute Members

DevExpress.Xpo Namespace