百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

StoredProcedureEFCore

> 编程语言
开源

用于执行存储过程的 Entity Framework Core 扩展

191 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

用于执行存储过程的 Entity Framework Core 扩展

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C#asp-net-corecsharpdotnet-coredotnetcore

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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