我在Windows 10上使用ArangoDB 3.1.19,使用ArangoDB .NET客户端(0.7.60,尝试0.7.50(均来自NuGET))。
在执行LINQ查询并使用Sort()或OrderBy时,结果将以未分类的方式返回(按自然/时间顺序排列)。
生成的查询似乎是正确的;如果我在ArangoDB Web界面中运行它会产生预期的结果。但是通过.NET客户端它不是。
代码:
[CollectionProperty(CollectionName = "users")]
class User
{
[DocumentProperty(Identifier=IdentifierType.Key)]
public string Key { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
static void Main(string[] args)
{
ArangoDatabase.ChangeSetting(o => {
o.Url = "http://localhost:8529";
o.Database = "test";
o.Logger = new ArangoDB.Client.DatabaseLogSharedSetting() {
HttpRequest = true,
Aql = true,
Log = log => Debug.WriteLine(log),
};
});
using (ArangoDatabase db = new ArangoDatabase())
{
var query = db.Query<User>()
.OrderBy(o => o.Name);
foreach (User user in query)
Console.WriteLine(user.Name);
}
Console.ReadLine();
}
输出:
jimmy
tony
ozzy
bjork
调试输出:
==============================
5/10/2017 2:21:28 PM
creating an AQL query:
query: for `o` in `users` sort `o`.`Name` asc return `o`
==============================
5/10/2017 2:21:28 PM
sending http request:
url: http://localhost:8529/_db/test/_api/cursor
method: POST
'ArangoConsoleTest.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'ArangoConsoleTest.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
data: {"query":" for `o` in `users` sort `o`.`Name` asc return `o`","options":{"optimizer":{"rules":[]}}}
==============================
5/10/2017 2:21:30 PM
received http response:
url: http://localhost:8529/_db/test/_api/cursor
status-code: Created
data: "{\"result\":[{\"_key\":\"jimmy\",\"_id\":\"users/jimmy\",\"_rev\":\"_U68WDkm---\",\"name\":\"jimmy\",\"age\":1},{\"_key\":\"1193\",\"_id\":\"users/1193\",\"_rev\":\"_U676wfm---\",\"name\":\"tony\",\"age\":42},{\"_key\":\"1432\",\"_id\":\"users/1432\",\"_rev\":\"_U674_PS---\",\"name\":\"ozzy\",\"age\":69},{\"_key\":\"1387\",\"_id\":\"users/1387\",\"_rev\":\"_U673Suy---\",\"name\":\"bjork\",\"age\":50}],\"hasMore\":false,\"cached\":false,\"extra\":{\"stats\":{\"writesExecuted\":0,\"writesIgnored\":0,\"scannedFull\":4,\"scannedIndex\":0,\"filtered\":0,\"executionTime\":0.0010030269622802734},\"warnings\":[]},\"error\":false,\"code\":201}"
答案 0 :(得分:0)
我明白了。在我的Collection(在ArangoDB中)中,Age和Name字段都是小写的(年龄和名称),但在我的模型类(.NET)中,它们是年龄/名称。
查询没有错误输出,所以我认为名称不区分大小写,但显然不是LINQ内容或排序。
将[DocumentProperty(PropertyName =&#34; name&#34;)]添加到我的Name属性中修复了排序问题。
答案 1 :(得分:0)
请看Pho答案是否有问题,另一个解决方案是如果会员名称是camelcase形式,您可以使用:
[DocumentProperty(Naming = NamingConvention.ToCamelCase)]
public string Name { get; set; }
或者如果所有成员都在camelcase中,请使用类属性作为命名约定
[CollectionProperty(Naming= NamingConvention.ToCamelCase)]
public class User
{ ... }
这样,所有成员名称将转换为加载文档中的camelcase表单(User -> user
),保存文档,AQL查询和其他操作。