使用参数从 .Net 调用 DocumentDb 存储过程。
Call DocumentDb stored procedure from .Net with parameters.
调用 sproc 工作正常,但我似乎无法将参数传递给它。它在 Azure 门户中按预期工作,但在从 .net 调用时却不是。
documentClient = new DocumentClient(new Uri(endpointUrl), authorizationKeyAdmin);
var sproc = documentClient.CreateStoredProcedureQuery(_companyCollection.StoredProceduresLink, "select * from root r where r.id = \"testSproc\"");
var result = documentClient.ExecuteStoredProcedureAsync<string>("dbs/GypNAB==/colls/GxpNAKrZMwA=/sprocs/GxpNAKrZMwxxxxAAAAAAAgA==/", sproc, "MyParameter");
存储过程并没有真正改变
function sample(rrid) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT top 1 * FROM c where c.RRID = "'+rrid+'"',
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) getContext().getResponse().setBody(rrid + 'no docs found!');
else getContext().getResponse().setBody(JSON.stringify(feed[0]));
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
从 .net 调用时的输出是“[object Object]未找到文档!”我希望 [Object Object] 成为我的参数值。如果我删除参数限制,我会得到正确的结果集。另外,如果我 运行 它带有 azure 参数,我会得到正确的结果集。
提前致谢。
ExecuteStoredProcedureAsync()
(sproc
) 的第二个参数映射到存储过程中的第一个参数 - 这就是 rrid
显示为 [object Object]
的原因在输出中。
尝试 运行:
var result = documentClient.ExecuteStoredProcedureAsync<string>("dbs/GypNAB==/colls/GxpNAKrZMwA=/sprocs/GxpNAKrZMwxxxxAAAAAAAgA==/", "MyParameter");
调用 sproc 工作正常,但我似乎无法将参数传递给它。它在 Azure 门户中按预期工作,但在从 .net 调用时却不是。
documentClient = new DocumentClient(new Uri(endpointUrl), authorizationKeyAdmin);
var sproc = documentClient.CreateStoredProcedureQuery(_companyCollection.StoredProceduresLink, "select * from root r where r.id = \"testSproc\"");
var result = documentClient.ExecuteStoredProcedureAsync<string>("dbs/GypNAB==/colls/GxpNAKrZMwA=/sprocs/GxpNAKrZMwxxxxAAAAAAAgA==/", sproc, "MyParameter");
存储过程并没有真正改变
function sample(rrid) {
var collection = getContext().getCollection();
// Query documents and take 1st item.
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT top 1 * FROM c where c.RRID = "'+rrid+'"',
function (err, feed, options) {
if (err) throw err;
// Check the feed and if empty, set the body to 'no docs found',
// else take 1st element from feed
if (!feed || !feed.length) getContext().getResponse().setBody(rrid + 'no docs found!');
else getContext().getResponse().setBody(JSON.stringify(feed[0]));
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
从 .net 调用时的输出是“[object Object]未找到文档!”我希望 [Object Object] 成为我的参数值。如果我删除参数限制,我会得到正确的结果集。另外,如果我 运行 它带有 azure 参数,我会得到正确的结果集。
提前致谢。
ExecuteStoredProcedureAsync()
(sproc
) 的第二个参数映射到存储过程中的第一个参数 - 这就是 rrid
显示为 [object Object]
的原因在输出中。
尝试 运行:
var result = documentClient.ExecuteStoredProcedureAsync<string>("dbs/GypNAB==/colls/GxpNAKrZMwA=/sprocs/GxpNAKrZMwxxxxAAAAAAAgA==/", "MyParameter");