【问题标题】:Method chaining in neo4jclient's return methodneo4jclient 的返回方法中的方法链
【发布时间】:2020-05-13 19:31:43
【问题描述】:

我无法弄清楚以下密码查询的 neo4jclient 等效项是什么:

match (n)
return n.Property, n.AnotherProperty, n.head(label(n))

这是我目前所拥有的:

.Match("n")
.Return((n) => new SomeNode
{
    Property = n.As<SomeNode>.Property,
    AnotherProperty = n.As<SomeNode>.AnotherProperty,
    Label = n.Labels() //This gives all labels, I only need the head. I can't chain it with ".head()"
}

我查看了 stackoverflow 以及 wiki,但找不到任何关于链接函数的信息。

有没有办法以我在这里描述的方式实现链接,我是否需要构造另一个查询来分别获取标签,然后获取该列表的头部并将其添加到 SomeNode,或者我错过了一个更好、完全不同的方法?

我最初是在遇到以下错误时到达这里的: “如果您想在 .NET 中运行客户端逻辑来重塑数据,请在执行查询后使用 Select 调用,例如 .Return(...).Results.Select(r => ...)。” 但是,wiki 上也没有这方面的示例。

【问题讨论】:

    标签: c# neo4j neo4jclient


    【解决方案1】:

    我能很快想到的最佳方法是使用Return.As 来处理您想在Return 中执行的任何此类操作,例如:

    .Match("(n)")
    .Return((n) => new SomeNode
    {
        Property = n.As<SomeNode>.Property,
        AnotherProperty = n.As<SomeNode>.AnotherProperty,
        Label = Return.As<string>("head(labels(n))")
    }
    

    您可以使用With:

    .Match("(n)")
    .With("n, head(labels(n)) AS firstLabel")
    .Return((n, firstLabel) => new SomeNode
    {
        Property = n.As<SomeNode>.Property,
        AnotherProperty = n.As<SomeNode>.AnotherProperty,
        Label = firstLabel.As<string>()
    }
    

    两者之间有很多区别 - 您必须将head 位写为string 任何一种方式:/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 2014-10-18
      相关资源
      最近更新 更多