本文介绍了PetaPoco 和存储过程的输出参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PetaPoco 设置输出参数.我发现有人在线使用此示例:

I'm trying to setup an output parameter using PetaPoco. I found someone using this sample online:

var ctx = new CustomDBDatabase();
var total = new SqlParameter("Total", System.Data.SqlDbType.Int);
total.Direction = System.Data.ParameterDirection.Output;

var results = ctx.Query<DBEntity>("exec GetDBEntities @StartIndex, @MaxIndex, @TotalCount = @Total out",
  id, start, max, total);

int totalCount = (int)total.Value;

但是,total.value 返回空值,即使当我直接对 SQL Server 运行此语句时,它也会返回 3. PetaPoco 的设置是否正确?是否支持输出参数?

However, total.value returns null, even though when I run this statement directly against SQL Server, it returns me 3. Is this setup correctly with PetaPoco? Are output parameters supported?

谢谢.

推荐答案

这是支持的.但无论如何,您当前的语法是错误的.

This is supported. But your current syntax is wrong anyways.

var ctx = new CustomDBDatabase();
var total = new SqlParameter("TotalCount", System.Data.SqlDbType.Int);
total.Direction = System.Data.ParameterDirection.Output;

var results = ctx.Query<DBEntity>("exec GetDBEntities @StartIndex, @MaxIndex, @TotalCount OUTPUT", new { StartIndex = start, MaxIndex = max, TotalCount = total});

int totalCount = (int)total.Value;

这样的东西应该可以工作.不太确定 sql 语法,但这应该可以帮助您.

Something like this should work though. Not quite sure of the sql syntax but this should get you on your way.

这篇关于PetaPoco 和存储过程的输出参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 21:57