Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dapper Contrib Output Parameter

I’m research about Dapper Contrib Storeprocedure and I donn’t know how to get value Output Parameter from the procedure, this is my store procedure:

ALTER PROC [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 store with Dapper Contrib?
Sorry for my bad English and Thank You.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading