Masterly.NonEmptyList.Dapper
3.0.1
dotnet add package Masterly.NonEmptyList.Dapper --version 3.0.1
NuGet\Install-Package Masterly.NonEmptyList.Dapper -Version 3.0.1
<PackageReference Include="Masterly.NonEmptyList.Dapper" Version="3.0.1" />
<PackageVersion Include="Masterly.NonEmptyList.Dapper" Version="3.0.1" />
<PackageReference Include="Masterly.NonEmptyList.Dapper" />
paket add Masterly.NonEmptyList.Dapper --version 3.0.1
#r "nuget: Masterly.NonEmptyList.Dapper, 3.0.1"
#:package Masterly.NonEmptyList.Dapper@3.0.1
#addin nuget:?package=Masterly.NonEmptyList.Dapper&version=3.0.1
#tool nuget:?package=Masterly.NonEmptyList.Dapper&version=3.0.1
Masterly.NonEmptyList.Dapper
Dapper type handlers for Masterly.NonEmptyList. Non-empty collections are stored as JSON text columns and NonEmptyString as text; reading an empty or blank column fails instead of producing an empty value.
Installation
dotnet add package Masterly.NonEmptyList.Dapper
Usage
Register once at startup:
using Masterly.NonEmptyList.Dapper;
NonEmptyDapper.AddTypeHandlers<string>(); // NonEmptyList<string>, ImmutableNonEmptyList<string>, NonEmptySet<string>
NonEmptyDapper.AddDictionaryHandler<string, int>(); // NonEmptyDictionary<string, int>
NonEmptyDapper.AddConstrainedHandler<int, AtLeast<Two>>(); // ConstrainedList<int, AtLeast<Two>>
NonEmptyDapper.AddNonEmptyStringHandler(); // NonEmptyString and NonEmptyString?
NonEmptyDapper.AddTypeHandlersFor<ProductRow>(); // scans a DTO and registers everything it needs
NonEmptyDapper.AddTypeHandler<OrderLines>(); // any [NonEmptyCollection]-generated class
Then use Dapper as usual:
public sealed class ProductRow
{
public long Id { get; set; }
public NonEmptyString Name { get; set; }
public NonEmptyList<string>? Tags { get; set; }
}
connection.Execute("INSERT INTO Products (Id, Name, Tags) VALUES (@Id, @Name, @Tags)", row);
ProductRow back = connection.QuerySingle<ProductRow>("SELECT * FROM Products WHERE Id = @id", new { id });
Column values are plain JSON (["a","b"]), so they remain queryable with your database's JSON functions. Reading [], whitespace or invalid JSON raises DataException naming the type. Nullable properties read NULL as null.
All registrations are idempotent. Pass JsonSerializerOptions to any Add... method to control element serialization.
Documentation
Full guide: https://a7mdfre7at.github.io/Masterly.NonEmptyList/docs/serialization.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Dapper (>= 2.1.66)
- Masterly.NonEmptyList (>= 3.0.1)
-
net8.0
- Dapper (>= 2.1.66)
- Masterly.NonEmptyList (>= 3.0.1)
-
net9.0
- Dapper (>= 2.1.66)
- Masterly.NonEmptyList (>= 3.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v3.0.1:
- New package icon: a pair of brackets around a single element
v3.0.0:
- Initial release: NonEmptyDapper.AddTypeHandlers<T>() registers JSON handlers for every non-empty collection of T
- NonEmptyStringTypeHandler for text columns that must have content