[英]Dapper Contrib Output Parameter
I'm research about Dapper Contrib stored procedure and I don't know how to get value output parameter from the procedure.我正在研究 Dapper Contrib 存储过程,但我不知道如何从该过程中获取值 output 参数。
This is my stored procedure:这是我的存储过程:
ALTER PROCEDURE [dbo].[spCustomPaging]
@SkipCount INT,
@PageSize INT, /*record in 1 page*/
@TotalRows INT OUTPUT /*tong record*/
AS
BEGIN
SET NOCOUNT ON;
SELECT @TotalRows = COUNT(*)
FROM dbo.Product
SELECT *
FROM dbo.Product
ORDER BY ProductID
OFFSET @SkipCount ROW FETCH NEXT @PageSize ROWS ONLY
And this is my Dapper contrib query:这是我的 Dapper 贡献查询:
db.Query<Models.Product>("spCustomPaging", new { SkipCount = skip, PageSize = pageSize }, commandType: System.Data.CommandType.StoredProcedure);
How I can get the TotalRow from the stored procedure with Dapper Contrib?如何使用 Dapper Contrib 从存储过程中获取 TotalRow?
Sorry for my bad English and thank you.抱歉我的英语不好,谢谢。
You can try to use DynamicParameters
be the parameter that can declare ParameterDirection.Output
for the parameter which you want to be output, then we can use Get<int>
to get the output value.您可以尝试使用
DynamicParameters
作为可以声明ParameterDirection.Output
的参数作为您希望为 output 的参数,然后我们可以使用Get<int>
获取 output 值。
var params = new DynamicParameters();
params.Add("@SkipCount",skip);
params.Add("@PageSize",pageSize);
params.Add("@TotalRows", dbType: DbType.Int32, direction: ParameterDirection.Output);
db.Query<Models.Product>("spCustomPaging", params, commandType: System.Data.CommandType.StoredProcedure);
var output = params.Get<int>("@TotalRows");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.