ColumnDefaultValueAttribute Class
Applied to persistent class’ fields or properties. Specifies the default value of the database column mapped to the target property/field.
Namespace: DevExpress.Xpo
Assembly: DevExpress.Xpo.v24.2.dll
Declaration
Remarks
The passed value is converted according to the current DBMS specifics and passed to the CREATE TABLE and ALTER TABLE statements when updating the database schema.
This attribute specifies the default value of a database column that XPO creates for the decorated property. The code sample below demonstrates how to use the ColumnDefaultValueAttribute to set a default value for the VacationDays column.
int vacationDays;
[ColumnDefaultValue(28)]
public int VacationDays {
get { return vacationDays; }
set { SetPropertyValue<int>(nameof(VacationDays), ref vacationDays, value); }
}
If the corresponding database table already has records and does not have the corresponding column (VacationDays in the example above) yet, these existing records will have the specified value when XPO adds this column.
However, new records will not have this value, since it will be overridden with an actual value of a new persistent object. To specify the default value of a new persistent object, override the PersistentBase.AfterConstruction() method.