SpocR 4.1.35

dotnet tool install --global SpocR --version 4.1.35
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local SpocR --version 4.1.35
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=SpocR&version=4.1.35
                    
nuke :add-package SpocR --version 4.1.35
                    

SpocR Publish NuGet NuGet Badge

  • Scaffolds your Stored Procedures and Models to C# Files
  • Easily managed through a CLI interface
  • Scalable and extensible architecture
  • No rigid dependencies for maximum flexibility

How SpocR works

SpocR extracts your database schema via a provided ConnectionString and stores it in a spocr.json configuration file. This configuration file is highly customizable, allowing you to select which schemas to include or exclude.

SpocR generates a complete DataContext folder structure with all required C# code for your .NET application (App, API, or Services).

The tool is designed for flexibility. You can:

  • Build it as a standalone project (Default mode)
  • Use it as a library to integrate into other projects (Library mode)
  • Create extensions to enhance existing SpocR libraries (Extension mode)

SpocR supports User-Defined Table Functions and various parameter types. The results of your Stored Procedures will be automatically mapped to strongly-typed models or as List<Model>. It also supports pure JSON-string results from Stored Procedures without building additional model classes.

Generated Folder Structure

./DataContext/
  ├── Models/[schema]/[StoredProcedureName].cs
  ├── StoredProcedures/[schema]/[EntityName]Extensions.cs
  ├── TableTypes/[schema]/[TableTypeName].cs
  ├── AppDbContext.cs
  ├── AppDbContextExtensions.cs
  ├── SqlDataReaderExtensions.cs
  └── SqlParameterExtensions.cs

Using the generated SpocR code

Step 1: Register the context

Register IAppDbContext in your application's dependency injection container:

// .NET 6+ in Program.cs
builder.Services.AddAppDbContext();

// Or in Startup.cs for older versions
services.AddAppDbContext();

Step 2: Inject the context

Inject IAppDbContext into your business logic components:

private readonly IAppDbContext _dbContext;

public MyManager(IAppDbContext dbContext)
{
    _dbContext = dbContext;
}

Step 3: Call stored procedures

Use the generated extension methods to call your stored procedures:

public Task<List<UserList>> ListAsync(CancellationToken cancellationToken = default)
{
    return _dbContext.UserListAsync(User.Id, cancellationToken);
}

Naming Conventions

StoredProcedure Naming Pattern

[EntityName][Action][Suffix]
  • EntityName (required): Name of the base SQL table
  • Action (required): Create | Update | Delete | (Merge, Upsert) | Find | List
  • Suffix (optional): WithChildren | [custom suffix]

Required Result Format for CRUD Operations

For Create, Update, Delete, Merge, and Upsert operations, stored procedures should return:

  • [ResultId] INT: Operation result status
  • [RecordId] INT: ID of the affected record

Technical Requirements

  • Database: SQL Server version 2012 or higher
  • Framework: .NET Core / .NET 6+ (supports down to .NET Core 2.1)
  • Current Version: 4.0.0 (as of April 2025)

Required .NET Packages

  • Microsoft.Data.SqlClient
  • Microsoft.Extensions.Configuration

Installation Guide

First, ensure you have the .NET SDK installed (latest version recommended)

dotnet tool install --global SpocR

Option B: Install from GitHub Source

# Clone the repository
git clone https://github.com/nuetzliches/spocr.git

# Uninstall previous versions if needed
dotnet tool uninstall -g spocr

# Build and install from source
cd src
(dotnet msbuild -t:IncrementVersion)
dotnet pack --output ./ --configuration Release
dotnet tool install -g spocr --add-source ./

Using SpocR

Quick Start

To quickly set up your project:

# Create and configure spocr.json
spocr create

# Pull schemas and build DataContext
spocr rebuild

Step-by-Step Approach

If you prefer more control:

# Step 1: Pull database schemas and update spocr.json
spocr pull

# Step 2: Build DataContext folder
spocr build

Removing SpocR

To remove SpocR configuration and/or generated code:

spocr remove

Advanced Configuration

Project Role Types in spocr.json

Project.Role.Kind

  • Default: Creates a standalone project with all dependencies
  • Lib: Creates a SpocR library for integration into other projects, including AppDbContext and dependencies
  • Extension: Creates an extensible project without AppDbContext and dependencies to extend an existing SpocR library. Requires configuring the namespace (Project.Role.LibNamespace) to resolve the SpocR library

Sample Implementation

For a complete example project with stored procedures and API implementation, visit: https://github.com/nuetzliches/nuts

Additional Resources

Known Issues and Limitations

  • SQL Server cannot reliably determine the nullable property for computed columns. For cleaner models, wrap computed columns in ISNULL({computed_expression}, 0) expressions.
  • When using complex types as parameters, ensure they follow the required table type structure.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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.

This package has no dependencies.

Version Downloads Last Updated
4.1.35 124 8/4/2025
4.1.34 123 8/4/2025
4.1.33 127 8/4/2025
4.1.32 112 6/6/2025
4.1.31 141 6/5/2025
4.1.30 191 4/29/2025
4.1.29 180 4/29/2025
4.1.28 170 4/29/2025
4.1.27 193 4/24/2025
4.1.26 182 4/24/2025
4.1.25 192 4/24/2025
4.1.24 181 4/23/2025
4.1.23 178 4/23/2025
4.1.22 181 4/23/2025
4.1.21 168 4/23/2025
4.1.20 180 4/23/2025
4.1.19 186 4/23/2025
4.1.18 173 4/23/2025
4.1.17 179 4/23/2025
4.1.4 179 4/22/2025
4.0.1 182 4/22/2025
3.2.3 163 7/10/2024
3.2.2 331 11/20/2023
3.2.1 218 11/20/2023
3.1.14 294 4/18/2023
3.1.12 328 2/9/2023
3.1.11 378 1/27/2023
3.1.10 342 1/27/2023
3.1.9 402 11/17/2022
3.1.7 470 10/18/2022
3.1.6 467 10/4/2022
3.1.4 475 9/13/2022
3.1.3 519 6/30/2022
3.1.2 525 6/30/2022
3.1.1 503 6/30/2022
3.1.0 494 6/30/2022
3.0.5 540 5/17/2022
3.0.3 488 5/17/2022
3.0.2 510 4/26/2021
3.0.1 492 4/26/2021
3.0.0 472 4/20/2021
2.0.4 446 4/9/2021
2.0.3 522 3/12/2021
2.0.2 488 3/11/2021
1.5.20 489 2/9/2021
1.5.16 540 12/3/2020
1.5.15 540 12/3/2020
1.5.14 569 9/25/2020
1.5.13 600 9/22/2020
1.5.12 570 9/22/2020
1.5.11 598 9/21/2020
1.5.10 636 9/20/2020
1.5.7 593 9/17/2020
1.5.4 604 9/17/2020
1.5.3 599 9/16/2020
1.5.2 646 9/15/2020
1.5.1 606 8/14/2020
1.5.0 674 4/17/2020
1.4.6 649 3/20/2020
1.4.5 634 3/6/2020
1.4.4 612 3/2/2020
1.4.3 612 2/27/2020
1.4.2 667 2/27/2020
1.4.1 631 2/7/2020
1.4.0 636 2/6/2020
1.3.7 620 2/5/2020
1.3.6 628 2/3/2020
1.3.5 634 1/31/2020
1.3.4 641 1/31/2020
1.3.3 665 1/30/2020
1.3.0 691 1/27/2020
1.2.3 755 1/8/2020
1.2.2 657 11/21/2019
1.2.1 645 11/21/2019
1.2.0 630 11/7/2019
1.1.7.4 694 10/10/2019
1.1.7 689 10/10/2019
1.1.6 699 9/24/2019
1.1.5 681 9/11/2019
1.1.4 669 9/11/2019
1.1.3 657 9/5/2019
1.1.2 705 8/21/2019
1.1.1 693 7/25/2019
1.0.6 676 7/22/2019
1.0.5 698 7/17/2019
1.0.4 738 6/9/2019
1.0.3 729 6/7/2019
1.0.2 748 6/5/2019
1.0.1 764 6/5/2019
1.0.0 707 5/29/2019
0.2.0 830 4/23/2019
0.1.3 750 4/12/2019
0.1.1 792 4/11/2019