我只想从RethinkDB
table
中检索1个元素,但是看来我做不到。
我已经尝试过RunCursor
,但是我不能像OrderBy
所说的那样与API
一起使用。即使返回的类型必须使用Nth
也无法进行优化仍然是数组。
POCO
class KnownMessage{
public long timestamp1{get;set;}
}
方法1:和RunResult
KnownMessage[] lastFinishedGame = await r.Db(Constants.DB_NAME)
.Table(Constants.MESSAGE_TABLE)
.Filter([some filtering])
.OrderBy("timestamp1")
.Nth(0)
.RunResultAsync<KnownMessage[]>(this.con);
错误
Message: Newtonsoft.Json.JsonSerializationException : Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Server.Domain.KnownMessage]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'r[0].data'.
方法2 与RunCursor
:
Cursor<KnownMessage> lastFinishedGame = await r.Db(Constants.DB_NAME)
.Table(Constants.MESSAGE_TABLE)
.Filter([some filtering])
.OrderBy("timestamp1")
.Nth(0)
.RunCursorAsync<KnownMessage>(this.con);
错误
The query response cannot be converted to a Cursor<T>. The run helper works with SUCCESS_SEQUENCE or SUCCESS_PARTIAL results. The server response was SUCCESS_ATOM. If the server response can be handled by this run method check T. Otherwise, if the server response cannot be handled by this run helper use `.RunAtom<T>` or `.RunResult<T>`.
问题是,我希望只返回一个文档,而且似乎无法表达这一点,除非使用nth
,它仍然可以围绕一个集合进行解析。
PS 我不想将数组包装在另一个对象中!