Class NullPolicyAttribute
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
Declares what a NULL does to a member when a row is mapped: on the model type for every member, or on one member.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property|AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public sealed class NullPolicyAttribute : Attribute
- Inheritance
-
NullPolicyAttribute
- Inherited Members
Examples
[NullPolicy(NullAction.Throw)]
public sealed class Post
{
public int Id { get; init; }
[NullValue(0)]
public int Likes { get; init; }
[NullPolicy(NullAction.Default)]
public string Title { get; init; } = "(untitled)";
}
Remarks
A policy always applies, nullable members included. On the type it covers every member, and a member's own policy overrides it (None included). A NullValueAttribute on a member overrides any policy, the member's own included. A positional record's parameter takes the policy on the parameter or on its property. A pair or a converter of a RowMap<T> that names the member is explicit and overrides the member's own declarations in that map (the type's policy still covers it); a converter whose column type is a Nullable<T> receives the NULL itself, and no policy applies. 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. A policy on a base type covers a derived model's members. The nearest declaration wins: the derived type's own policy, then its base type's; a member's own policy beats both, and a NullValueAttribute beats all. The declarations are read once per type, when its slots are built.
Every check costs one NULL test per covered member per row. A member with no policy is not checked (None).
Constructors
- NullPolicyAttribute(NullAction)
Declares what a NULL does to a member when a row is mapped: on the model type for every member, or on one member.
Properties
- Action
Gets what a NULL does.