asp.net-mvc-4 - 使用 dapper 将输出参数传递给接受数据表作为参数的 sp

标签 asp.net-mvc-4 dapper

嗨,作为学习的一部分,我正在研究 mvc,所以我遇到了一种情况,我必须将数据表传递给 sp,同时我必须提供一个 int 的输出参数 也是类型。目前我正在使用此代码

con.Execute("XXXXXXX",
 new { @LoginId = LoginId, @City= City, @RegionCode = RegionCode, @CarList= Cars, @CompCOde = COmp},
 commandType: CommandType.StoredProcedure);

这里的 Cars 是一个数据表,所以我想为此添加一个输出参数,请建议我一个解决方案。

最佳答案

我将创建一个参数列表,其中一个指定为 ParameterDirection.Output,然后您将能够使用 Get 从中读取内容。

我对以下示例做了一些假设,包括 int 输出参数(未测试)

            SqlConnection con = new SqlConnection();
            DynamicParameters p = new DynamicParameters();
            p.Add("@LoginId", LoginId, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
            p.Add("@City", City, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
            p.Add("@RegionCode", RegionCode, dbType: DbType.VarNumeric, direction: ParameterDirection.Input);
            p.Add("@CarList", Cars.AsTableValuedParameter());
            p.Add("@SomeId", dbType: DbType.Int32, direction: ParameterDirection.Output);
            con.Execute("XXXXXXX",p,commandType: CommandType.StoredProcedure);

            int someId = p.Get<int>("@SomeId");

关于asp.net-mvc-4 - 使用 dapper 将输出参数传递给接受数据表作为参数的 sp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43463174/

相关文章:

c# - 每分钟从 API 获取数据到我的服务器

c# - 如何教 User.IsInRole

c# - 如何使 serviceStack.ormlite 或 Dapper 中的映射依赖于列类型?

c# - Dapper 提供者依赖参数 token

c# - 如何使用MVC4在部分 View 中调用HtmlHelper方法

c# - MembershipCreateUserException - 提供的用户名无效

c# - @indexName 附近的语法不正确。衣冠楚楚

performance - 使用 Dapper 进行批量插入花费的时间比预期的要长

c# - 有没有办法通过字符串或索引访问 Dapper FastExpando 中的列?

c# - SignalR 与 ASP.NET MVC 和 WinForms