Table of Contents

Constructor NullValueAttribute

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

NullValueAttribute(object?)

Declares the value a NULL gives a member when a row is mapped: the member is checked for NULL, and a NULL is replaced with the value.

public NullValueAttribute(object? value)

Parameters

value object

The value a NULL gives the member: null, a string, a bool, a char, a number or an enum value.

Examples

public sealed class Post
{
    [NullValue(0)]
    public int Likes { get; init; }

    [NullValue("(untitled)")]
    public string Title { get; init; } = "";
}

Remarks

It always applies, nullable members included, and it overrides any NullPolicyAttribute: the type's, and the member's own. It costs one NULL test per row. A pair or a converter of a RowMap<T> that names the member overrides it in that map, as it does a member's policy. A converter whose column type is a reference type (string) is not called for a NULL; the member then follows the NULL rules and the type's policy.

The value is a constant: null, a string, a bool, a char, a number or an enum value. It is converted to the member's type (its underlying type for a Nullable<T>) as a column's value is, when the map is created: text to a DateTime or a Guid, a number to an enum or to another number type. A value of another kind (a Type, an array), or one that does not convert, throws ArgumentException when the map is created.

See Also