0

I'm research about Dapper Contrib stored procedure and I don't know how to get value output parameter from the procedure.

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:

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?

Sorry for my bad English and thank you.

0

1 Answer 1

0

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.

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.