Skip to main content
.NET Framework 4.5.2+

KeyAttribute.AutoGenerate Property

Gets or sets whether the key is generated automatically.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

public bool AutoGenerate { get; set; }

Property Value

Type Description
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.

public class Customer : XPBaseObject {
    int oid;
    [Key(true)]
    public int Oid { 
        get { return oid; } 
        set { SetPropertyValue(nameof(Oid), ref oid, value); } 
    }
    // ...
}
See Also