DbThing 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DbThing --version 1.0.0
                    
NuGet\Install-Package DbThing -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DbThing" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbThing" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DbThing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DbThing --version 1.0.0
                    
#r "nuget: DbThing, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DbThing@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DbThing&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DbThing&version=1.0.0
                    
Install as a Cake Tool

DbThing

What is it?

It's a thing, for your database. More specifically, a thing that lets you query the database and map the results of the queries to C# objects.
You can write you own mapping method or you can let the source generator write it for you.

Quick Samples

Models

Manual

This is a model that has it's mapping method manually written.

using DbThing;

namespace ApiExample;

public class PersonManual : IDbModel
{
    public int PersonId { get; set; }
    public DateTime HireDate { get; set; }
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public string? Title { get; set; }
    
    public void Initialize(Dictionary<string, object> values)
    {
        PersonId = values.TryGetRequired<int>("BusinessEntityId");
        HireDate = values.TryGetRequired<DateTime>("HireDate");
        FirstName = values.TryGetRequired<string>("FirstName");
        LastName = values.TryGetRequired<string>("LastName");
        Title = values.TryGet<string>("Title");
    }
}
Source Generated

This is a model who will have it's mapping method (Initialize in the above example) generated at build time.

using Attributes;
using DbThing;

namespace ApiExample;

public partial class Person : IDbPreProcessModel, IDbModel
{
    [DbColumn("BusinessEntityID", Required = true)]
    public int PersonId { get; set; }
    
    [DbColumn("HireDate", Required = true)]
    public DateTime HireDate { get; set; }

    [DbColumn("FirstName", Required = true)]
    public string FirstName { get; set; } = string.Empty;
    
    [DbColumn("LastName", Required = true)]
    public string LastName { get; set; } = string.Empty;
    
    [DbColumn("Title")]
    public string? Title { get; set; }
}

Querying

This example assumes you're building a minimal api, like in the example project included in this repo.

<.NET minimal api boilerplate>

var repo = var repo = new DbRepository(builder.Configuration);

app.MapGet("/person/{name}", ([FromRoute] string name) => {
    var result = repo.QueryAsync<Person>("usp_get_persons_whose_first_name_is", [new SqlParameter("@name", name)]);
    return result;
})
.WithName("FirstNames");
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 158 8/27/2025
1.0.0 482 7/22/2025