PetaPoco 和存储过程的输出参数?

发布于 2024-12-22 17:10:44 字数 521 浏览 6 评论 0原文

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

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 返回 null,即使当我直接针对 SQL Server 运行此语句时,它也会返回我 3. 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;

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?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2024-12-29 17:10:44

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

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 语法,但这应该可以帮助您上路。

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;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文