使用.OrderByDescending

时间:2015-09-23 14:17:14

标签: neo4j neo4jclient

我不知道如何做到这一点,我希望它是非常简单的东西,我想做的就是按时间戳排序这些结果,但我不知道在哪里放弃不抛出的.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();

我想按'working.startDate'排序(C#long),我被告知可以进行排序,然后将生成的对象转换为EmployerObject,但这没有多大意义。 使用Neo4j 2.2.5和2个版本的客户端(对于项目的不同区域,一个来自NuGet本周下载,另一个作为git源,但我不能在我的生活中计算出版本号,所以解决方案是可以接受的。)

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

1 个答案:

答案 0 :(得分:1)

是的,您需要的秘诀是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),您将无法对数据执行操作。