有没有一种方法来调用与精致小巧的存储过程?方法来、存储过程、小巧、精致

2023-09-02 21:31:35 作者:你打不过我的

我pssed与小巧玲珑的微型ORM 的结果stackoverflow.com很IM $ P $。我正在考虑为我的新的项目,但我觉得有些时候我的项目需要有存储过程一个担心,我有搜索了很多网站,但没有发现与存储过程的任何事情。那么,有没有办法让小巧精致的做工与存储过程?

I am very impressed with the results of Dapper Micro ORM for stackoverflow.com. I am considering it for my new project and but I have one concern about that some times my project requires to have Stored Procedure and I have search a lot on web but not found anything with stored procedure. So is there any way to have Dapper work with a stored procedure?

请让我知道,如果可能的话,否则我必须把它延长我的路。

Please let me know if it is possible otherwise I have to extend it in my way.

推荐答案

我刚刚检查了丰富的支持特效:

I just checked in rich support for procs:

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

In the simple case you can do:

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

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

If you want something more fancy, you can do:

 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,但是这是比较笨重。

Additionally you can use exec in a batch, but that is more clunky.