.net - 有没有办法用 Dapper 调用存储过程?

标签 .net stored-procedures orm dapper

Dapper Micro ORM的结果给我留下了深刻的印象对于 stackoverflow.com。我正在考虑将其用于我的新项目,但我担心有时我的项目需要存储过程,并且我在网络上进行了很多搜索,但没有找到任何带有存储过程的内容。那么有什么方法可以让 Dapper 使用存储过程吗?

如果可能,请告诉我,否则我必须以我的方式扩展它。

最佳答案

在简单的情况下,你可以这样做:

var user = cnn.Query<User>("spGetUser", new {Id = 1}, 
        commandType: CommandType.StoredProcedure).First();

如果你想要更奇特的东西,你可以这样做:

 var p = new DynamicParameters();
 p.Add("@a", 11);
 p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
 p.Add("@c", dbType: DbType.Int32, direction: ParameterDirection.ReturnValue);

 cnn.Execute("spMagicProc", p, commandType: CommandType.StoredProcedure); 

 int b = p.Get<int>("@b");
 int c = p.Get<int>("@c"); 

此外,您可以批量使用 exec,但这比较笨重。

关于.net - 有没有办法用 Dapper 调用存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5962117/

相关文章:

node.js - 不能删除类型 "enum_TableName_column",因为其他对象依赖于它。 (PostgreSQL、Sequelize、Node.js)

node.js - 播种时运行 sequelize 模型 Hook

c# - 为什么选项卡页面主体不使用 .NET 选项卡控件进行更新?

MYSQL存储过程删除

sql - 按 : 分区的 Row_Number() 性能优化

asp.net-mvc - SQL Server 存储过程减慢查询速度

.net - 如何在 .NET 中以 ORM 友好的方式存储可扩展元数据?

.net - 如何停止一个线程直到 n 个线程完成它们的工作

c# - 读取可能不存在的 Azure DocumentDB 文档

.net - 结合依赖注入(inject)和动态切面编织