我的DocumentDB SP
:
function getSetOfProductDetails(productIds) {
var collection = getContext().getCollection();
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
"SELECT * FROM product WHERE product.productId IN ("+ productIds +")" ,
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) getContext().getResponse().setBody(feed);
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
我的C#代码:
string productIdList = "'271762','288738','235521','266714'";
List<Product> productList = new List<Product>();
try
{
productList = await DocumentDBRepository<List<Product>>.ExecuteStoredProc("product","getSetOfProductDetails", productIdList );
}
DocumentDBRepository代码:
public static async Task<T> ExecuteStoredProc(string collectionId, string storedProcedureId, params object[] parameter)
{
ConnectToDatabase();
StoredProcedureResponse<T> document = await _documentClient.ExecuteStoredProcedureAsync<T>(UriFactory.CreateStoredProcedureUri(_databaseId, collectionId, storedProcedureId), parameter);
return (T)(dynamic)document;
}
我在productList
收到的结果集是空白的,而Collection
中有文档。这是实施IN
的{{1}}语句的正确方法吗?
答案 0 :(得分:0)