繁体   English   中英

运行原始的mycouch查询

[英]run a primitive mycouch query

我是不熟悉长沙发和mycouch的人。 我正在尝试实现一个非常简单的查询,我只想获取视图的结果并将其保存到我的DTO类中。

当我通过HTTP手动查询时,我的ouchdb查询有效:

http://localhost:5984/mydb/_design/tshirts/_view/getAllTshirts

但是,当我尝试使用mycouch从我的应用程序运行它时,我无法运行它。 我当前的查询:

using MyCouch.Requests;
using MyCouch.Responses;

// (...)

using (var client = new Client("http://localhost:5984/samples")) {
    var query = new QueryViewRequest("getAllTshirts");

    ViewQueryResponse<TShirt[]> result = await client.Views.QueryAsync<TShirt[]>(query);
    Console.WriteLine (result);
}

由于某种原因,它将找不到Client类。 我发现了一个在github上使用Client的示例,如您所见,我正在使用与示例中所有MyCouch相关的名称空间。

我还尝试使用MyCouchStore代替:

using (var store = new MyCouchStore("http://localhost:5984/", "samples")) {
    var query = new QueryViewRequest("getAllTshirts");
    ViewQueryResponse<TShirt[]> result = await store.Views.QueryAsync<TShirt[]>(query);
    Console.WriteLine (result);
}

但是, store不包含任何名为Views属性。 有什么想法如何使用MyCouch查询我的视图吗?

这就是我使用MyCouchStore所做的

using (var store = new MyCouchStore("http://user:password@localhost:5984", "samples")) {
    var query = new Query("tshirts", "getAllTshirts");

    var rows = store.QueryAsync<TShirt>(query).Result;
}

显然,该文档不是最新的。 构造函数现在需要2个参数,第二个是可选的引导程序。 这为我工作:

var client = new Client("http://localhost:5984/samples", null)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM