This project has been developed with the .NET Standart 2.1 and allows you to call stored procedure from the database by simply creating only interface and methods signature without needing any concrete class to call any stored procedure. It can work async and sync. It provides stored procedure support for MsSQL and MySQL, function support for PostgreSQL.
$ dotnet add package BctSPThis project has been developed with the .NET Standard 2.1. It allows you to call stored procedures and functions from the database by simply creating only the interface and methods signature without needing any concrete class to call any stored procedure and function. It can work async and sync. It provides stored procedure and function support for MsSQL, MySQL, PostgreSQL and OracleSQL
BctSP is now available on NuGet. If interested, you can easily install it using the NuGet Package Manager. It can be accessed through the link https://www.nuget.org/packages/BctSP.
To utilize the BctSP NuGet package, you can follow these phases:
builder.Services.AddBctSp((x) =>
{
// x.BctSpConnectionStringOrConfigurationPath = "Server=...";
x.BctSpConnectionStringOrConfigurationPath = "Databases:ConnectionString";
x.DatabaseType = BctSpDatabaseType.PostgreSql;
});
[BctSpAttribute("GetProductsByPrice", BctSP.Enums.BctSpCommandType.StoredProcedure)]
public class GetProductsByPriceRequest : BctSpBaseRequest<GetProductsByPriceResponse>
{
public decimal ProductPrice { get; set; }
}
Customized Usage
The database configuration can be overridden and customized for each request if needed.
[BctSpAttribute("GetProductsByPrice", BctSP.Enums.BctSpCommandType.StoredProcedure,"CustomDatabases:ConnectionString",BctSP.Enums.BctSpDatabaseType.MsSql))]
public class GetProductsByPriceRequest : BctSpBaseRequest<GetProductsByPriceResponse>
{
public decimal ProductPrice { get; set; }
}
//[BctSpAttribute("GetProductsByPrice", BctSP.Enums.BctSpCommandType.StoredProcedure,"Server=...",,BctSP.Enums.BctSpDatabaseType.MsSql))]
//public class GetProductsByPriceRequest : BctSpBaseRequest<GetProductsByPriceResponse>
//{
// public decimal ProductPrice { get; set; }
//}
public class GetProductsByPriceResponse : BctSpBaseResponse
{
public string ProductName { get; set; }
public decimal ProductPrice { get; set; }
public string ProductDescription { get; set; }
}
public interface ISampleSP : IBctSp
{
List<GetProductsByPriceResponse> GetProductsByPrice(GetProductsByPriceRequest request);
Task<List<GetProductsByPriceResponse>> GetProductsByPriceAsync(GetProductsByPriceRequest request);
}
public class WeatherForecastController
{
private readonly ISampleSP _sampleSp;
public WeatherForecastController(ISampleSP sampleSp)
{
_sampleSp = sampleSp;
}
Sample Usage
public List<GetProductsByPriceResponse> GetProductsByPrice()
{
var response = _sampleSp.GetProductsByPrice(new GetProductsByPriceRequest{ ProductPrice = 100 });
return response;
}
public async Task<List<GetProductsByPriceResponse>> GetProductsByPriceAsync()
{
var response = await _sampleSp.GetProductsByPriceAsync(new GetProductsByPriceRequest{ ProductPrice = 100 });
return response;
}
Contributors