我在 C# 中使用 Neo4jClient 和 Neo4j 图形数据库,我想知道如何使用 Neo4jClient 检索所有节点。
这是密码查询,用于检索所有与“KNOWS”有关系的节点,而与关系方向无关:
start n =node(*) match n-[r:KNOWS]-(friend) return friend;
这是带有 Neo4jClient 的 C# 代码:
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
var cypherFluentQueryReturned = client.RootNode
.StartCypher("n")
.Match("n-[:KNOWS]->friend")
.Return<Node<Person>>("friend");
但是 Neo4jClient 不允许从 * 中检索所有节点,而只能从起点检索,这里是根节点。
我如何使用 Neo4jClient 来检索所有节点,而不仅仅是附加到根节点的节点?
似乎没有办法通过 Neo4jClient.GraphClient 从 * 查询节点。
但是我可以通过使用 RawGraphClient 执行查询来做到这一点:
CypherQuery query = new CypherQuery("start n=node(*) match n-[KNOWS]-(person) return person", new Dictionary<string, object>(), CypherResultMode.Set);
var persons = ((IRawGraphClient)client).ExecuteGetCypherResults<Person>(query).ToList();
使用 Node<T>.StartCypher(identity)
是创建查询并一次启动所有查询的快捷方式。
相反,直接从客户端创建您的查询:
client
.Cypher
.Start(new { n = All.Nodes })
.Return<object>("n")
然后,您就可以完全控制 START
条款。
我是一名优秀的程序员,十分优秀!