gpt4 book ai didi

c# - Neo4jClient C#如何获取所有节点

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:59 24 4
gpt4 key购买 nike

我在 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条款。

关于c# - Neo4jClient C#如何获取所有节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12884172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com