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

Stored procedures 存储过程中的PetaPoco和输出参数?,stored-procedures,petapoco,output-parameter,Stored Procedures,Petapoco,Output Parameter,我正在尝试使用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 GetDBEnt

我正在尝试使用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;
var ctx=new CustomDBDatabase();
var total=新的SqlParameter(“total”,System.Data.SqlDbType.Int);
total.Direction=System.Data.ParameterDirection.Output;
var results=ctx.Query(“exec GetDBEntities@StartIndex、@MaxIndex、@TotalCount=@Total out”,
id、开始、最大值、总计);
int totalCount=(int)total.Value;
但是,
total.value
返回null,即使我直接在SQL Server上运行此语句时,它返回3。PetaPoco的设置正确吗?是否支持输出参数


谢谢。

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

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;
var ctx=new CustomDBDatabase();
var total=新的SqlParameter(“TotalCount”,System.Data.SqlDbType.Int);
total.Direction=System.Data.ParameterDirection.Output;
var results=ctx.Query(“exec GetDBEntities@StartIndex,@MaxIndex,@TotalCount OUTPUT”,new{StartIndex=start,MaxIndex=max,TotalCount=total});
int totalCount=(int)total.Value;

不过,像这样的方法应该行得通。不太确定sql语法,但这应该可以帮助您解决问题。

如何为MySql编写类似的代码?使用MySql语法调用SP。如果您还需要返回值怎么办?