0

我在 .net 客户端上使用聚合的 storedproc lumenize https://github.com/lmaccherone/documentdb-lumenize时遇到问题。尝试将参数传递并查询到存储过程时出现错误。下面是我的代码

 public async static void QuerySP()        {
            using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
            {
                //Get the Database
                var database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).ToArray().FirstOrDefault();

                //Get the Document Collection
                var collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();

                StoredProcedure storedProc = client.CreateStoredProcedureQuery(collection.StoredProceduresLink).Where(sp => sp.Id == "cube").ToArray().FirstOrDefault();             


                dynamic result =  await client.ExecuteStoredProcedureAsync<dynamic>(storedProc.SelfLink, "{cubeConfig: {groupBy: 'publication', field: 'pid', f: 'count'}, filterQuery: 'SELECT pid, publication FROM c'}");
                Console.WriteLine("Result from script: {0}\r\n", result.Response);
            }
}

执行代码时出现以下错误

消息:{“错误”:[“执行 Javascript 时遇到异常。异常 = 错误:需要 cubeConfig 或 savedCube\r\n堆栈跟踪:错误:需要 cubeConfig 或 savedCube\n at fn (cube.js:1803:7)\n在 __docDbMain (cube.js:1844:5)\n 在未知脚本代码 (cube.js:1:2)"]}

不知道我做错了什么。我非常感谢您的帮助。谢谢。

4

2 回答 2

1

你几乎拥有它。问题是您将 cubeConfig 作为字符串发送。它必须是一个对象。这是执行此操作的代码:

string cubeConfigString = @"{
    cubeConfig: {
        groupBy: 'publication', 
        field: 'pid', 
        f: 'count'
    }, 
    filterQuery: 'SELECT * FROM c'
}";

Object cubeConfig = JsonConvert.DeserializeObject<Object>(cubeConfigString);
Console.WriteLine(cubeConfig);

dynamic result = await client.ExecuteStoredProcedureAsync<dynamic>("dbs/dev-test-database/colls/dev-test-collection/sprocs/cube", cubeConfig);

Console.WriteLine(result.Response);
于 2015-12-08T17:36:46.000 回答
1

我的工作代码

public async static Task QuerySP2()
    {
        using (client = new DocumentClient(new Uri(endpointUrl), authorizationKey))
        {
            //Get the Database
            var database = client.CreateDatabaseQuery().Where(db => db.Id == databaseId).ToArray().FirstOrDefault();

            //Get the Document Collection
            var collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == collectionId).ToArray().FirstOrDefault();

            StoredProcedure storedProc = client.CreateStoredProcedureQuery(collection.StoredProceduresLink).Where(sp => sp.Id == "cube").ToArray().FirstOrDefault();

            string filterQuery = string.Format(@"SELECT * from c");

            string cubeConfigString = @"{
                cubeConfig: {
                    groupBy: 'publication', 
                    field: 'id', 
                    f: 'count'
                }, 
                filterQuery: '" + filterQuery + "'}";

            dynamic cubeConfig = JsonConvert.DeserializeObject<dynamic>(cubeConfigString);
            Console.WriteLine(cubeConfig);

            string continuationToken = null;

            dynamic result=null;
            do
            {


                var queryDone = false;
                while (!queryDone)
                {
                    try
                    {
                        result = await client.ExecuteStoredProcedureAsync<dynamic>(storedProc.SelfLink, cubeConfig);
                        cubeConfig = result.Response;
                        continuationToken = cubeConfig.continuation;
                        queryDone = true;
                    }
                    catch (DocumentClientException documentClientException)
                    {
                        var statusCode = (int)documentClientException.StatusCode;
                        if (statusCode == 429 || statusCode == 503)
                            System.Threading.Thread.Sleep(documentClientException.RetryAfter);
                        else
                            throw;
                    }
                    catch (AggregateException aggregateException)
                    {
                        if (aggregateException.InnerException.GetType() == typeof(DocumentClientException))
                        {

                            var docExcep = aggregateException.InnerException as DocumentClientException;
                            var statusCode = (int)docExcep.StatusCode;
                            if (statusCode == 429 || statusCode == 503)
                                System.Threading.Thread.Sleep(docExcep.RetryAfter);
                            else
                                throw;
                        }
                    }
                }



            } while (continuationToken != null);

            Console.WriteLine("Result from script: {0}\r\n", result.Response);


        }


    }
于 2015-12-10T03:05:40.727 回答