CSharpDB.Service
1.7.0
Prefix Reserved
dotnet add package CSharpDB.Service --version 1.7.0
NuGet\Install-Package CSharpDB.Service -Version 1.7.0
<PackageReference Include="CSharpDB.Service" Version="1.7.0" />
<PackageVersion Include="CSharpDB.Service" Version="1.7.0" />
<PackageReference Include="CSharpDB.Service" />
paket add CSharpDB.Service --version 1.7.0
#r "nuget: CSharpDB.Service, 1.7.0"
#:package CSharpDB.Service@1.7.0
#addin nuget:?package=CSharpDB.Service&version=1.7.0
#tool nuget:?package=CSharpDB.Service&version=1.7.0
CSharpDB.Service
Compatibility facade for hosting CSharpDB in ASP.NET Core, Blazor, or MCP server applications.
Overview
CSharpDB.Service now delegates to CSharpDB.Client.
Its purpose is transition compatibility for existing in-process hosts that still inject CSharpDbService. The authoritative database API lives in CSharpDB.Client; this package preserves the old DI shape, events, and model surface while the repo retires direct service usage.
Features
- Compatibility layer: Existing hosts can keep injecting
CSharpDbService - Thread-safe wrapper: Calls are serialized via
SemaphoreSlim - DI-ready: Constructor still reads the
"CSharpDB"connection string fromIConfiguration - Event bridge: Preserves
TablesChanged,SchemaChanged, andProceduresChanged - Delegates to client: Schema, CRUD, SQL, procedures, saved queries, and diagnostics now flow through
CSharpDB.Client
Usage
ASP.NET Core Registration
// appsettings.json
{
"ConnectionStrings": {
"CSharpDB": "Data Source=myapp.db"
}
}
// Program.cs
builder.Services.AddSingleton<CSharpDbService>();
Service API
using CSharpDB.Service;
public class MyController(CSharpDbService db)
{
// Browse a table with pagination
public async Task<TableBrowseResult> GetUsers(int page = 1)
=> await db.BrowseTableAsync("users", page, pageSize: 25);
// Get a single row by primary key
public async Task<Dictionary<string, object?>> GetUser(string pk)
=> await db.GetRowByPkAsync("users", pk);
// Insert a row
public async Task CreateUser(Dictionary<string, string?> values)
=> await db.InsertRowAsync("users", values);
// Execute arbitrary SQL
public async Task<SqlExecutionResult> RunSql(string sql)
=> await db.ExecuteSqlAsync(sql);
// Schema introspection
public async Task<List<string>> GetTables()
=> await db.GetTableNamesAsync();
// Storage diagnostics
public async Task<object> InspectDatabase()
=> await db.InspectStorageAsync();
}
Schema Management
// DDL operations
await db.CreateIndexAsync("users", "idx_email", "email", isUnique: true);
await db.CreateViewAsync("active_users", "SELECT * FROM users WHERE active = 1");
await db.RenameTableAsync("users", "app_users");
await db.AddColumnAsync("app_users", "created_at", "TEXT");
await db.DropColumnAsync("app_users", "legacy_field");
Storage Diagnostics
// Inspect the database file
var report = await db.InspectStorageAsync();
// Check WAL integrity
var walReport = await db.CheckWalAsync();
// Inspect a specific page
var pageInfo = await db.InspectPageAsync(pageId: 5);
// Verify all indexes
var indexReport = await db.CheckIndexesAsync();
Procedure Catalog
using CSharpDB.Core;
using CSharpDB.Service.Models;
await db.CreateProcedureAsync(new ProcedureDefinition
{
Name = "GetUserById",
BodySql = "SELECT * FROM users WHERE id = @id;",
Parameters =
[
new ProcedureParameterDefinition
{
Name = "id",
Type = DbType.Integer,
Required = true,
}
],
IsEnabled = true,
CreatedUtc = DateTime.UtcNow,
UpdatedUtc = DateTime.UtcNow,
});
var execution = await db.ExecuteProcedureAsync("GetUserById", new Dictionary<string, object?>
{
["id"] = 1L,
});
Result Models
| Model | Description |
|---|---|
SqlExecutionResult |
Query/DML result with IsQuery, ColumnNames, Rows, RowsAffected, Error, Elapsed |
TableBrowseResult |
Paginated table data with Schema, Rows, TotalRows, Page, PageSize, TotalPages |
ViewBrowseResult |
View query results |
ViewDefinition |
View name and defining SQL |
ProcedureDefinition |
Procedure metadata: name, body SQL, params, enabled flag, timestamps |
ProcedureExecutionResult |
Procedure execution summary with per-statement results and rollback-safe error info |
Installation
dotnet add package CSharpDB.Service
For the recommended all-in-one package:
dotnet add package CSharpDB
Dependencies
CSharpDB.Client- authoritative database APICSharpDB.Sql- SQL splitting for compatibility event notificationsMicrosoft.Extensions.Configuration.Abstractions- configuration binding
Related Packages
| Package | Description |
|---|---|
| CSharpDB.Data | Underlying ADO.NET provider |
| CSharpDB.Engine | Embedded database engine |
License
MIT - see LICENSE for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- CSharpDB.Client (>= 1.7.0)
- CSharpDB.Sql (>= 1.7.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on CSharpDB.Service:
| Package | Downloads |
|---|---|
|
CSharpDB
All-in-one package for CSharpDB application development. Includes the unified client, engine, ADO.NET provider, service layer, and diagnostics. |
GitHub repositories
This package is not used by any popular GitHub repositories.