CSharpDB.Service
1.2.0
Prefix Reserved
See the version list below for details.
dotnet add package CSharpDB.Service --version 1.2.0
NuGet\Install-Package CSharpDB.Service -Version 1.2.0
<PackageReference Include="CSharpDB.Service" Version="1.2.0" />
<PackageVersion Include="CSharpDB.Service" Version="1.2.0" />
<PackageReference Include="CSharpDB.Service" />
paket add CSharpDB.Service --version 1.2.0
#r "nuget: CSharpDB.Service, 1.2.0"
#:package CSharpDB.Service@1.2.0
#addin nuget:?package=CSharpDB.Service&version=1.2.0
#tool nuget:?package=CSharpDB.Service&version=1.2.0
CSharpDB.Service
Thread-safe service layer for hosting CSharpDB in ASP.NET Core, Blazor, or MCP server applications.
Overview
CSharpDB.Service wraps the CSharpDB ADO.NET provider in a thread-safe service class designed for dependency injection in web applications. It provides a complete API surface for schema operations, CRUD, DDL, SQL console execution, and storage diagnostics. Reads the CSharpDB connection string from IConfiguration.
Features
- Thread-safe: All operations are serialized via
SemaphoreSlim - DI-ready: Constructor takes
IConfiguration, reads the"CSharpDB"connection string - Full schema operations: Tables, indexes, views, triggers (create, update, drop)
- CRUD: Browse (paginated), get by PK, insert, update, delete
- SQL console:
ExecuteSqlAsyncwith multi-statement splitting and timing - Storage diagnostics: Database inspection, WAL checking, page inspection, index verification
- Events:
TablesChangedandSchemaChangedfor UI refresh
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();
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 |
Installation
dotnet add package CSharpDB.Service
Dependencies
CSharpDB.Data- ADO.NET providerCSharpDB.Storage.Diagnostics- storage inspection toolkitMicrosoft.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.Data (>= 1.2.0)
- CSharpDB.Storage.Diagnostics (>= 1.2.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 engine, ADO.NET provider, service layer, and diagnostics. |
GitHub repositories
This package is not used by any popular GitHub repositories.