CSharpDB.Service 1.2.0

dotnet add package CSharpDB.Service --version 1.2.0
                    
NuGet\Install-Package CSharpDB.Service -Version 1.2.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="CSharpDB.Service" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharpDB.Service" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="CSharpDB.Service" />
                    
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 CSharpDB.Service --version 1.2.0
                    
#r "nuget: CSharpDB.Service, 1.2.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 CSharpDB.Service@1.2.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=CSharpDB.Service&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=CSharpDB.Service&version=1.2.0
                    
Install as a Cake Tool

CSharpDB.Service

Thread-safe service layer for hosting CSharpDB in ASP.NET Core, Blazor, or MCP server applications.

NuGet License: MIT

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: ExecuteSqlAsync with multi-statement splitting and timing
  • Storage diagnostics: Database inspection, WAL checking, page inspection, index verification
  • Events: TablesChanged and SchemaChanged for 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 provider
  • CSharpDB.Storage.Diagnostics - storage inspection toolkit
  • Microsoft.Extensions.Configuration.Abstractions - configuration binding
Package Description
CSharpDB.Data Underlying ADO.NET provider
CSharpDB.Engine Embedded database engine

License

MIT - see LICENSE for details.

Product 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. 
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.2.0 0 3/5/2026
1.1.0 36 3/4/2026