Class ValueObjectTypeHandler<TSelf, TValue>
Namespace: AdCodicem.ValueObjects.Dapper
Assembly: AdCodicem.ValueObjects.Dapper.dll
Maps a value object to and from its underlying column value for Dapper.
public sealed class ValueObjectTypeHandler<TSelf, TValue> : SqlMapper.TypeHandler<TSelf>, SqlMapper.ITypeHandler where TSelf : struct, IValueObject<TSelf, TValue>
Type Parameters
TSelf
Value object type.
TValue
Underlying value type.
Inheritance
object ← SqlMapper.TypeHandler<TSelf> ← ValueObjectTypeHandler<TSelf, TValue>
Implements
SqlMapper.ITypeHandler
Inherited Members
SqlMapper.TypeHandler<TSelf>.SetValue(IDbDataParameter, TSelf), SqlMapper.TypeHandler<TSelf>.Parse(object), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Reading uses the trusted factory, on the same reasoning as the Entity Framework Core converter: the rows come
from a database this application wrote through the validating factory, and read paths are hot. A column holding
text where the underlying type is not text, or the reverse, is the exception: the value object did not write it.
Text read into a value object whose underlying type is not uuid or uniqueidentifier one - is converted to
text, then validated through TryCreate.
A parameter declares the column a value object over
A SQL NULL reads as null into an optional value object, TSelf?, and is refused
with a
For a member of a mapped type, or a parameter of the constructor it is mapped through, Dapper checks for a
NULL before it calls the handler, and never calls it: a required value object is left uninitialized,
default(TSelf), and nothing throws. A column that can be NULL belongs in a TSelf? member.
Methods
Parse(object)
Parse a database value back to a typed value
public override TSelf Parse(object value)
Parameters
value object
The value from the database
Returns
TSelf
The typed value
Exceptions
value is a SQL NULL, which a value object cannot hold, a value that cannot be
converted to TValue, or text, or a value converted to text, that the value object
refuses.
SetValue(IDbDataParameter, TSelf)
Assign the value of a parameter before a command executes
public override void SetValue(IDbDataParameter parameter, TSelf value)
Parameters
parameter IDbDataParameter
The parameter to configure
value TSelf
Parameter value