简体   繁体   English

neo4jclient获取节点标签

[英]neo4jclient get node labels

How do i get the labels of a node with Neo4jClient library 如何使用Neo4jClient库获取节点的标签

this is the code i ran and it returned the following error 这是我运行的代码,它返回以下错误

The return expression that you have provided uses methods other than those defined by ICypherResultItem, Neo4jClient.Cypher.All or Neo4jClient.Cypher.Return. 您提供的返回表达式使用的方法不是ICypherResultItem,Neo4jClient.Cypher.All或Neo4jClient.Cypher.Return定义的方法。 The return expression needs to be something that we can translate to Cypher, then send to the server to be executed. return表达式必须是可以转换为Cypher的东西,然后发送到服务器执行。 You can't use chains of methods, LINQ-to-objects, or other constructs like these. 您不能使用方法链,LINQ到对象或类似的其他构造。 If you want to run client-side logic to reshape your data in .NET, use a Select call after the query has been executed, like .Return(…).Results.Select(r => …). 如果要运行客户端逻辑以在.NET中重塑数据,请在执行查询后使用Select调用,例如.Return(…).Results.Select(r =>…)。 This technique maintains a clear separation between what is being executed server-side (in Neo4j, via Cypher) versus client-side (back in .NET). 这项技术在服务器端(在Neo4j中,通过Cypher)和客户端(在.NET中)之间保持了清晰的区分。

my code 我的代码

public List<string> getLabels(MyEvent targetEvent)
{
    List<string> result = 
                        this.client.Cypher.Match("(newE:MyEvent)")
                            .Where((MyEvent newE) => newE.myid == targetEvent.myid)
                            .Return(newE=> newE.Labels().ToString())
                            .Results.ToList();
                    return result;
}

The docs section " Get all labels for a specific user " show this code: docs部分“ 获取特定用户的所有标签 ”显示以下代码:

graphClient.Cypher
    .Match("(user:User)")
    .Where((User user) => user.Id == 1234)
    .Return(user => user.Labels())
    .Results

Based in the error message in the question, I believe you only need to remove the toString() from the return, like this: 基于问题中的错误消息,我相信您只需要从返回中删除toString() ,如下所示:

public List<string> getLabels(MyEvent targetEvent)
{
    List<string> result = this.client.Cypher.Match("(newE:MyEvent)")
        .Where((MyEvent newE) => newE.myid == targetEvent.myid)
        .Return( newE=> newE.Labels() )
        .Results.ToList();
        return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM