DbThing 1.0.0
See the version list below for details.
dotnet add package DbThing --version 1.0.0
NuGet\Install-Package DbThing -Version 1.0.0
<PackageReference Include="DbThing" Version="1.0.0" />
<PackageVersion Include="DbThing" Version="1.0.0" />
<PackageReference Include="DbThing" />
paket add DbThing --version 1.0.0
#r "nuget: DbThing, 1.0.0"
#:package DbThing@1.0.0
#addin nuget:?package=DbThing&version=1.0.0
#tool nuget:?package=DbThing&version=1.0.0
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 | 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
- Attributes (>= 1.0.0)
- DbThing.Common (>= 1.0.0)
- Microsoft.Data.SqlClient (>= 5.2.1)
- Microsoft.Extensions.Configuration (>= 9.0.0-rc.1.24431.7)
- Serilog (>= 4.1.0-dev-02238)
- System.Linq (>= 4.3.0)
- System.Linq.Expressions (>= 4.3.0)
- System.Linq.Queryable (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.