A newer version of this page is available. Switch to the current version.

NullValueAttribute Class

Associates a constant with the null value of a property or a field of a simple type.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v18.2.dll


[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class NullValueAttribute :
<AttributeUsage(AttributeTargets.Property Or AttributeTargets.Field, Inherited:=True)>
Public NotInheritable Class NullValueAttribute
    Inherits Attribute


The NullValueAttribute is provided for compatibility with .NET Framework 1.x which doesn't have support for nullable types. The NullValueAttribute allows null values to be stored in a database and displayed in a UI. Whenever XPO stores a property or a field value to a database or supplies it to a data-bound control, the value is compared with the constant associated with a null value. If they are equal, null (Nothing in VB) is returned for the property or field instead of the associated value. Similarly, when the property's value is retrieved from the database or the data-bound control, it is compared with a null value. If these values are equal, the NullValueAttribute.Value is returned.

public class Example : XPObject {
    public int NullOnMinValueFieldInt;
    public int NullOnZeroFieldInt;
    public string NullOnEmptyStringFieldString;
    public string NullOnNULLFieldString;

Note that nullable types are supported by XPO under .NET Framework 2.0 and later.


See Also