Sprocit 0.1.0
dotnet add package Sprocit --version 0.1.0
NuGet\Install-Package Sprocit -Version 0.1.0
<PackageReference Include="Sprocit" Version="0.1.0" />
<PackageVersion Include="Sprocit" Version="0.1.0" />
<PackageReference Include="Sprocit" />
paket add Sprocit --version 0.1.0
#r "nuget: Sprocit, 0.1.0"
#:package Sprocit@0.1.0
#addin nuget:?package=Sprocit&version=0.1.0
#tool nuget:?package=Sprocit&version=0.1.0
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 | Versions 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. |
-
net8.0
- Dapper (>= 2.1.35)
- Microsoft.CodeAnalysis.Common (>= 4.11.0)
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Options (>= 8.0.2)
- MySql.Data (>= 9.0.0)
- System.Data.SqlClient (>= 4.8.6)
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 |