Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

StoredProcedureEFCore

> 编程语言
Open source

Entity Framework Core extension to execute stored procedures

191 stars0 likes0 views
WebsiteGitHub

About

Entity Framework Core extension to execute stored procedures

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

Example

csharp
List rows = null;

ctx.LoadStoredProc("dbo.ListAll")
   .AddParam("limit", 300L)
   .AddParam("limitOut", out IOutParam limitOut)
   .Exec(r => rows = r.ToList());

long limitOutValue = limitOut.Value;

ctx.LoadStoredProc("dbo.ReturnBoolean")
   .AddParam("boolean_to_return", true)
   .ReturnValue(out IOutParam retParam)
   .ExecNonQuery();

bool b = retParam.Value;

ctx.LoadStoredProc("dbo.ListAll")
   .AddParam("limit", 1L)
   .ExecScalar(out long l);

API

DbContext

csharp
IStoredProcBuilder LoadStoredProc(string name)

IStoredProcBuilder

…

DbDataReader

csharp
Task>                        ToListAsync();
Task>       ToDictionaryAsync(Func keyProjection);
Task>> ToLookupAsync(Func keyProjection);
Task>                     ToSetAsync();
Task>                        ColumnAsync();
Task>                        ColumnAsync(string columnName);
Task                              FirstAsync();
Task                              FirstOrDefaultAsync();
Task                              SingleAsync();
Task                              SingleOrDefaultAsync();

All these methods have a corresponding async method : ToListAsync, ToDictionaryAsync, ...

Installation

Install-Package StoredProcedureEFCore

Why ?

Stored procedure execution was previously not supported in Entity Framework Core:

  • Raw store access APIs: Support for ad hoc mapping of arbitrary types #1862
  • Stored procedure mapping support #245

It is now supported since EF Core 2.1 but this library 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. Output parameters and return values seem difficult to use with EF Core
  • Mapping is 30% faster

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C#asp-net-corecsharpdotnet-coredotnetcore

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言