StoredProcedureEFCore 0.3.11
See the version list below for details.
dotnet add package StoredProcedureEFCore --version 0.3.11
NuGet\Install-Package StoredProcedureEFCore -Version 0.3.11
<PackageReference Include="StoredProcedureEFCore" Version="0.3.11" />
paket add StoredProcedureEFCore --version 0.3.11
#r "nuget: StoredProcedureEFCore, 0.3.11"
// Install StoredProcedureEFCore as a Cake Addin #addin nuget:?package=StoredProcedureEFCore&version=0.3.11 // Install StoredProcedureEFCore as a Cake Tool #tool nuget:?package=StoredProcedureEFCore&version=0.3.11
Execute stored procedures with Entity Framework Core
DbContext extension with LoadStoredProc method which creates an IStoredProcBuilder to build a stored procedure with a custom mapping strategy using the provided DbDataReader extension.
The method handles :
- Extra column in result set
- Extra property in model
- Null values in result set
- Underscores in result set column names ("column_name" is mapped to ColumnName property)
- Int (db) to enumeration (result model) mapping
Entity Framework Core supports stored procedure since 2.1
This library will soon be obsolete, but it has few advantages compared to FromSql:
- Extra property in the model won't throw an exception. The property keeps its default value
- The interface is easier to use (I think). Output parameters and return values seem difficult to use with EFCore
- It is 30% faster
Example
List<Model> rows = null;
ctx.LoadStoredProc("dbo.ListAll")
.AddParam("limit", 300L)
.AddParam("limitOut", out IOutParam<long> limitOut)
.Exec(r => rows = r.ToList<Model>());
long limitOutValue = limitOut.Value;
ctx.LoadStoredProc("dbo.ReturnBoolean")
.AddParam("boolean_to_return", true)
.ReturnValue(out IOutParam<bool> retParam)
.ExecNonQuery();
bool b = retParam.Value;
ctx.LoadStoredProc("dbo.ListAll")
.AddParam("limit", 1L)
.ExecScalar(out long l);
API
DbContext
IStoredProcBuilder LoadStoredProc(string name)
DbDataReader
List<T> ToList<T>()
Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(Func<TValue, TKey> keyProjection)
Dictionary<TKey, List<TValue>> ToLookup<TKey, TValue>(Func<TValue, TKey> keyProjection)
HashSet<T> ToSet<T>()
List<T> Column<T>()
List<T> Column<T>(string columnName)
T First<T>()
T FirstOrDefault<T>()
T Single<T>()
T SingleOrDefault<T>()
All these methods have a corresponding async method : ToListAsync, ToDictionaryAsync, ...
IStoredProcBuilder
IStoredProcBuilder AddParam<T>(string name, T val) // Input parameter
IStoredProcBuilder AddParam<T>(string name, T val, out IOutParam<T> outParam) // Input/Ouput parameter
IStoredProcBuilder AddParam<T>(string name, out IOutParam<T> outParam) // Ouput parameter
IStoredProcBuilder ReturnValue<T>(out IOutParam<T> retParam)
void Exec(Action<DbDataReader> action)
void ExecNonQuery()
void ExecScalar<T>(out T val)
Exec, ExecNonQuery, and ExecScalar have a corresponding async method.
Installation
Install-Package StoredProcedureEFCore
Why ?
Stored procedure execution was not supported in entity framework core:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.3
- Microsoft.EntityFrameworkCore.Design (>= 1.0.1)
- NETStandard.Library (>= 1.6.1)
- System.Data.Common (>= 4.3.0)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on StoredProcedureEFCore:
Package | Downloads |
---|---|
BinaryBlox.SDK
Package Description |
|
BinaryBlox.SDK.Account
Package Description |
|
BinaryBlox.SDK.Configuration
Package Description |
|
BinaryBlox.SDK.Permission
Package Description |
|
DevDiamond.AspNetCore.JqueryDataTable
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.5 | 471,311 | 11/15/2020 | |
1.0.4 | 85,597 | 6/16/2020 | |
1.0.3 | 1,226 | 6/15/2020 | |
1.0.2 | 11,246 | 4/10/2020 | |
1.0.1 | 14,803 | 2/13/2020 | |
1.0.0 | 8,563 | 1/14/2020 | |
0.3.15 | 18,681 | 10/30/2019 | |
0.3.14 | 5,542 | 10/22/2019 | |
0.3.13 | 1,336 | 10/17/2019 | |
0.3.12 | 1,702 | 8/9/2019 | |
0.3.11 | 16,087 | 6/1/2019 | |
0.3.10 | 22,654 | 11/15/2018 | |
0.3.9 | 9,898 | 5/4/2018 | |
0.3.8 | 2,269 | 4/21/2018 | |
0.3.7 | 1,995 | 4/3/2018 | |
0.3.6 | 2,055 | 3/16/2018 | |
0.3.5 | 1,828 | 3/16/2018 | |
0.3.4 | 2,087 | 3/2/2018 | |
0.3.3 | 2,127 | 2/1/2018 | |
0.3.2 | 1,970 | 1/19/2018 | |
0.3.1 | 1,986 | 1/8/2018 | |
0.3.0 | 1,990 | 1/8/2018 | |
0.2.0 | 2,104 | 12/29/2017 | |
0.1.1 | 2,079 | 12/28/2017 | |
0.1.0 | 1,987 | 12/26/2017 |