使用 .OrderByDescending

Using .OrderByDescending

我不知道该怎么做,我希望这是非常简单的事情,我想做的就是按时间戳对这些结果进行排序,但我不知道将 .OrderByDescending 放在哪里'不会抛出错误。

public List<EmployerObject> My(string username)
    {
        return client.Cypher
            .Match("(person:Person)-[worked:WORKED_AT]->(employer:Employer)-[:IN_TOWN]-(town)-[:IN_CITY]-(city)-[:IN_STATE]-(state)-[:IN_COUNTRY]-(country)")
            .Where((Person person) => person.Email == username)
            .Return((person, employer, worked, town, city, state, country) => new EmployerObject
            {
                Person = person.As<Person>(),
                Employer = employer.CollectAs<Employer>(),
                Worked = worked.CollectAs<Worked>(),
                Town = town.CollectAs<Town>(),
                City = city.CollectAs<City>(),
                State = state.CollectAs<State>(),
                Country = country.CollectAs<Country>()
            })
            .Results.ToList();

我想按 'worked.startDate'(C# long)排序,有人告诉我可以进行排序,然后将生成的对象转换为 EmployerObject,但这毫无意义。 使用 Neo4j 2.2.5 和 2 个版本的客户端(针对项目的不同领域,本周从 NuGet 下载一个,另一个作为 git 源,但我无法在我的生活中计算出版本号,所以两者的解决方案都是可以接受的)。

任何帮助都是很好的帮助,谢谢。

是的,你需要的秘诀是 WITH 语句,下面的代码应该适合你:

return client.Cypher
    .Match("(person:Person)-[worked:WORKED_AT]->(employer:Employer)-[:IN_TOWN]-(town)-[:IN_CITY]-(city)-[:IN_STATE]-(state)-[:IN_COUNTRY]-(country)")
    .Where((Person person) => person.Email == username)
    .With("person, worked, employer") //<-- New Line!
    .OrderBy("worked.StartDate")      //<-- New Line!
    .Return((person, employer, worked, town, city, state, country) => new EmployerObject
    {
        Person = person.As<Person>(),
        Employer = employer.CollectAs<Employer>(),
        Worked = worked.CollectAs<Worked>(),
        Town = town.CollectAs<Town>(),
        City = city.CollectAs<City>(),
        State = state.CollectAs<State>(),
        Country = country.CollectAs<Country>()
    })
    .Results.ToList();

至于原因 - WITH 语句允许您将一个查询的结果链接到另一个查询,您可以将其视为查询中间的 RETURN -允许您对数据执行操作,直到 RETURN(例如 ORDER BY)之后才能执行。