BigIntegerToNullableUInt128PropertyHandler

A property handler that maps an unsigned 128-bit integer column, which drivers expose as a BigInteger, into a nullable UInt128 property.

A property handler that maps an unsigned 128-bit integer column (for example, the ClickHouse UInt128 type, which drivers expose as a BigInteger) into a Nullable<UInt128> property.

This handler is compiled only for .NET 8 and later. It is not available on the netstandard2.0 target of the RepoDb package.

Overview

Name Description
Class BigIntegerToNullableUInt128PropertyHandler
Namespace RepoDb.PropertyHandlers
Package RepoDb
Implements IPropertyHandler<object, UInt128?>
Column type An unsigned 128-bit integer column (for example, the ClickHouse UInt128 type)
Property type UInt128?
Availability Not available on the netstandard2.0 target of the package; requires .NET 8 or later.

Conversions

Method Direction Description
Get Database to property Converts the value returned by the driver (a BigInteger, a UInt128, or any other integral type) into Nullable<UInt128>. null and DBNull are returned as null.
Set Property to database Converts the UInt128 into a BigInteger, to be written into the column. A null value is written as null.

Exceptions

Exception Thrown When
OverflowException The value is negative or outside of the range of a UInt128.
ArgumentException The type of the value returned by the driver is not supported.

Usability

Bind the handler to the property that maps to the UInt128 column.

Attribute

public class Ledger
{
    public int Id { get; set; }

    [Map("hash"), PropertyHandler(typeof(BigIntegerToNullableUInt128PropertyHandler))]
    public UInt128? Hash { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new ClickHouseConnection(connectionString))
{
    connection.Insert(new Ledger { Id = 1, Hash = null });
    var ledger = connection.Query<Ledger>(e => e.Id == 1).First();
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Ledger>()
    .PropertyHandler<BigIntegerToNullableUInt128PropertyHandler>(e => e.Hash);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Ledger, BigIntegerToNullableUInt128PropertyHandler>(e => e.Hash, new BigIntegerToNullableUInt128PropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type UInt128?:

PropertyHandlerMapper.Add<UInt128?, BigIntegerToNullableUInt128PropertyHandler>(new BigIntegerToNullableUInt128PropertyHandler(), true);

See Also