Lithe 1.3.2
dotnet add package Lithe --version 1.3.2
NuGet\Install-Package Lithe -Version 1.3.2
<PackageReference Include="Lithe" Version="1.3.2" />
<PackageVersion Include="Lithe" Version="1.3.2" />
<PackageReference Include="Lithe" />
paket add Lithe --version 1.3.2
#r "nuget: Lithe, 1.3.2"
#:package Lithe@1.3.2
#addin nuget:?package=Lithe&version=1.3.2
#tool nuget:?package=Lithe&version=1.3.2
🪶 Lithe
Micro-ORM built on top of Dapper.
Install (dotnet CLI)
dotnet add package Lithe
Usage: GetAsync<T>
GetAsync<T> builds a SELECT statement and queries by primary key. It follows these conventions:
- Table name:
typeof(T).Name - Key column:
[Key]when present, otherwiseIdor{TypeName}Id(case-insensitive) - Columns: all public readable instance properties (uses
[Column("Name")]when present)
Example:
using System.Data;
using Dapper;
using Lithe;
public sealed class User
{
public int UserId { get; set; }
public string Name { get; set; } = string.Empty;
}
public static async Task<User?> LoadUserAsync(IDbConnection connection, int id)
{
// Make sure the connection is open if your provider requires it.
return await connection.GetAsync<User>(id);
}
If your key property does not follow the {TypeName}Id convention, GetAsync<T> will throw an InvalidOperationException.
You can specify a custom name for the column mapping
public sealed class User
{
[Column("user_id")]
public int UserId { get; set; }
[Column("full_name")]
public string Name { get; set; } = string.Empty;
}
Transform on GET
Use [Transform("...")] to apply a raw SQL expression only on SELECT (GET).
This keeps INSERT using the real column name.
public sealed class Place
{
public Guid PlaceId { get; set; }
[Column("geom")]
[Transform("St_transform(geom, 4326)")]
public string Geometry { get; set; } = string.Empty;
}
Usage: GetManyAsync<T>
GetManyAsync<T> builds the same SELECT statement as GetAsync<T>, but returns a list.
public sealed class Service
{
public Guid ServiceId { get; set; }
public string Name { get; set; } = string.Empty;
}
public static async Task<IEnumerable<Service>> LoadServicesAsync(IDbConnection connection, Guid serviceId)
{
// Returns zero or more rows.
return await connection.GetManyAsync<Service>(serviceId);
}
Usage: InsertAsync<T>
InsertAsync<T> builds an INSERT with all public readable properties and executes it.
public sealed class Service
{
public Guid ServiceId { get; set; }
public string Name { get; set; } = string.Empty;
}
public static async Task<int> SaveServiceAsync(IDbConnection connection, Service service)
{
// Returns the number of affected rows.
return await connection.InsertAsync<Service>(service);
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 was computed. 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. |
-
net9.0
- Dapper (>= 2.1.66)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.