Skip to main content
.NET 6.0+

NullableAttribute Class

Applies to persistent class’ fields or properties. Specifies if a nullable column should be created when updating the database schema for the target property/field.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v23.2.dll

NuGet Package: DevExpress.Xpo

Declaration

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class NullableAttribute :
    Attribute

Remarks

To change the NullableAttribute value for the entire persistent class, apply the NullableBehaviorAttribute instead. To change this setting globally, use the static XpoDefault.NullableBehavior property.

The NullableAttribute does not apply to persistent objects’ reference type properties. XPO uses these properties as foreign keys and creates NULL columns for this type. You cannot change this behavior.

See Nullable Behavior and Nullable Columns for more information.

The code below demonstrates how to apply the NullableAttribute. The example generates a database table that allows null in the Age column and does not allow null in the Name column.

using DevExpress.Xpo;

// ...
using(UnitOfWork unitOfWork = new UnitOfWork(dataLayer)) {
    unitOfWork.UpdateSchema(typeof(Person));
}

// ...
class Person : XPObject {
    public Person(Session session) : base(session) { }
    string fName;
    int fAge;

    [Nullable(false)]
    public string Name {
        get {
            return fName;
        }
        set {
            SetPropertyValue(nameof(fName), ref fName, value);
        }
    }

    [Nullable(true)]
    public int Age {
        get {
            return fAge;
        }
        set {
            SetPropertyValue(nameof(fName), ref fAge, value);
        }
    }
}

Inheritance

Object
Attribute
NullableAttribute
See Also