Sprocit 0.1.0

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

Sprocit

Sprocit is an interface based stored procedure mapping library inspired by Refit that makes calling stored procedures easier.

You define an interface with methods that represent stored procedures and Sprocit will generate the necessary code to call them. The generated code uses Dapper to call stored procedures and map the results onto the objects you specified as the return type. Sprocit will compile the generated code into an assembly and return it as an implemention of the interface.

By default sprocit will directly map the method names and parameters to the names and parameters of the stored procedure. You can override this behavior by using the SprocitProcName attribute on the method to name the stored procedure, and the SprocitParamName attribute to name the parameters.

Instantiate an instance of your interface by using the Sprocit<T> extension method on your connection.

var mySprocit = connection.Sprocit<IMySprocitTest>();

Sprocit supports both SqlConnection and IDbConnection.

Installation

TODO

Examples

Defining an interface that maps the MovieRatings method to a stored procedure named GetMoviesByRating and maps a parameter named ratingMin to an SQL parameter named MinRating. The stored procedure returns a single result set that maps to IEnumerable<MovieRecord>.

public interface IMySprocitTest
{
    [SprocitProcName("GetMoviesByRating")]
    IEnumerable<MovieRecord> MoviesRatings([SprocitParamName("MinRating")] float ratingMin);
}

public record MovieRecord(int Movie_ID, string Title, int Release_Year, string Genre, string Director, int Duration, double Rating);

Using Sprocit in a console application

using Sprocit;
using System.Data.SqlClient;

SqlConnection connection = new SqlConnection(Environment.GetEnvironmentVariable("SqlServerConnectionString"));
var sprocit = connection.Sprocit<IMySprocitTest>();

var movies = sprocit.MoviesRatings(8.9f);
foreach (var movie in movies)
{
    Console.WriteLine(movie.Title);
}

Adding your interface to dependency injection and calling a stored procedure in an endpoint using minimal API

using Sprocit;

...

builder.Services.AddScoped( _ => (new SqlConnection(Environment.GetEnvironmentVariable("SqlServerConnectionString")!)).Sprocit<IMySprocitTest>());

...


app.MapGet("/testsprocit", (float rating, IMySprocitTest sprocit) => sprocit.MoviesRatings(rating))
.WithOpenApi();

Debugging

You can see the class that Sprocit generates by passing in an ILogger with the log level set to Trace.

connection.Sprocit<IMySprocitTest>(logger: logger);

Current Limitations

  • Sprocit only supports stored procedures that return a single result set and the result is IEnumerable<T>.
  • Sprocit only supports stored procedures that return a result set that can be mapped to a record or class with primitive type properties. Dapper does the mapping. So if Dapper can do it with it's default behavior, Sprocit can do it.
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 was computed.  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.

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
0.1.0 139 10/5/2024