更新:更新的答案是正确的
IEnumerable<T> QueryProc<T>(...)
返回值是一个数据集,由过程/函数通过select语句返回。
如果您的过程不返回表,则需要使用非泛型版本ExecuteProc
,它只返回受影响记录的数量。
要获取输出参数值,您需要在命令中访问参数:
((IDbDataParameter)dataConnection.Command.Parameters["parameter_name"]).Value
下面是来自 linq2db 测试的过程调用助手的示例,由 T4 模板生成:
public static int OUTREFTEST(this DataConnection dataConnection, decimal? PID, out decimal? POUTPUTID, ref decimal? PINPUTOUTPUTID, string PSTR, out string POUTPUTSTR, ref string PINPUTOUTPUTSTR)
{
var ret = dataConnection.ExecuteProc("TESTUSER.OUTREFTEST",
new DataParameter("PID", PID, DataType.Decimal),
new DataParameter("POUTPUTID", null, DataType.Decimal) { Direction = ParameterDirection.Output, Size = 22 },
new DataParameter("PINPUTOUTPUTID", PINPUTOUTPUTID, DataType.Decimal) { Direction = ParameterDirection.InputOutput, Size = 22 },
new DataParameter("PSTR", PSTR, DataType.NVarChar),
new DataParameter("POUTPUTSTR", null, DataType.NVarChar) { Direction = ParameterDirection.Output },
new DataParameter("PINPUTOUTPUTSTR", PINPUTOUTPUTSTR, DataType.NVarChar) { Direction = ParameterDirection.InputOutput });
POUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTID"]). Value);
PINPUTOUTPUTID = Converter.ChangeTypeTo<decimal?>(((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTID"]). Value);
POUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["POUTPUTSTR"]). Value);
PINPUTOUTPUTSTR = Converter.ChangeTypeTo<string> (((IDbDataParameter)dataConnection.Command.Parameters["PINPUTOUTPUTSTR"]).Value);
return ret;
}