从documentdb存储过程获取结果c#

时间:2016-01-28 06:58:05

标签: c# json azure-cosmosdb

如何从documetdb存储过程中获取结果数据?请参阅以下代码

public static object GetDocument(string CollectionName, string StoredProcedureName, List<object> ProcedureParams)
{
        Microsoft.Azure.Documents.StoredProcedure sproc = GetDocumentStoredProcedure(CollectionName, StoredProcedureName).Result;

        dynamic result = client.ExecuteStoredProcedureAsync<dynamic>(sproc.SelfLink, ProcedureParams);
        if (result != null)
        {
            var ssd = result.Response;
        }            
        return result;            
}

public static async Task<Microsoft.Azure.Documents.StoredProcedure> GetDocumentStoredProcedure(string CollectionName, string StoredProcedureName)
{
        Microsoft.Azure.Documents.DocumentCollection collection = GetDocumentCollection(CollectionName).Result; //Getting collection details from function

        if (client.CreateStoredProcedureQuery(collection.SelfLink).Where(coll => coll.Id == StoredProcedureName).ToArray().Any())
        {
            return client.CreateStoredProcedureQuery(collection.SelfLink).Where(coll => coll.Id == StoredProcedureName).ToArray().FirstOrDefault();
        }

        return await client.CreateStoredProcedureAsync(collection.SelfLink, new Microsoft.Azure.Documents.StoredProcedure
        {
            Id = StoredProcedureName
        });
}

错误:

  

System.Threading.Tasks.Task&GT;&#39;不包含&#39;响应&#39;

的定义

如果是json数据,则存储过程预期结果。请帮忙

1 个答案:

答案 0 :(得分:0)

尝试向您的第5行添加await,如下所示:

dynamic result = await client.ExecuteStoredProcedureAsync<dynamic>(sproc.SelfLink, ProcedureParams);