Neo4jClient 从所有关系中获取类型集合
Neo4jClient get collection of types from all relations
我正在尝试将在 Neo4j 图形界面中运行的特定查询转换为使用 C# 中的 Neo4jClient 的实现。
我想获取列表中结果节点的所有关系类型。这可以使用以下查询:
MATCH ()-[relations]-(p)
Where p.name = 'example'
RETURN count(relations) AS relCount, collect(type(relations)) as types limit 10
这导致
relCount
types
4
["died_in", "has_type", "was_born", "is_identified_by"]
2
["has_type", "is_identified_by"]
在 C# 中使用客户端时,我无法将 relations.type()
与 relations.CollectAs<List<string>>()
结合使用。
var q = client.Cypher
.Match(@"()-[relations]-(p)")
.Where("p.name = 'example'")
.Return((relations, p) => new
{
relCount = relations.Count(),
types = relations.CollectAs<List<string>>(),
});
所以最后我想要一个这样的对象:
[
{
relcount: 4,
types: ["died_in", "has_type", "was_born", "is_identified_by"]
},
{
relcount: 2,
types: ["has_type", "is_identified_by"]
}
]
有人能给我指出正确的方向吗?
您可以为此使用 .With()
语句:
var q = client.Cypher
.Match(@"()-[relations]-(p)")
.Where("p.name = 'example'")
.With("count(relations) AS relCount, collect(type(relations)) as types")
.Return((relCount, types) => new
{
relCount = relCount.As<int>(),
types = types.As<List<string>>(),
});
我正在尝试将在 Neo4j 图形界面中运行的特定查询转换为使用 C# 中的 Neo4jClient 的实现。
我想获取列表中结果节点的所有关系类型。这可以使用以下查询:
MATCH ()-[relations]-(p)
Where p.name = 'example'
RETURN count(relations) AS relCount, collect(type(relations)) as types limit 10
这导致
relCount | types |
---|---|
4 | ["died_in", "has_type", "was_born", "is_identified_by"] |
2 | ["has_type", "is_identified_by"] |
在 C# 中使用客户端时,我无法将 relations.type()
与 relations.CollectAs<List<string>>()
结合使用。
var q = client.Cypher
.Match(@"()-[relations]-(p)")
.Where("p.name = 'example'")
.Return((relations, p) => new
{
relCount = relations.Count(),
types = relations.CollectAs<List<string>>(),
});
所以最后我想要一个这样的对象:
[
{
relcount: 4,
types: ["died_in", "has_type", "was_born", "is_identified_by"]
},
{
relcount: 2,
types: ["has_type", "is_identified_by"]
}
]
有人能给我指出正确的方向吗?
您可以为此使用 .With()
语句:
var q = client.Cypher
.Match(@"()-[relations]-(p)")
.Where("p.name = 'example'")
.With("count(relations) AS relCount, collect(type(relations)) as types")
.Return((relCount, types) => new
{
relCount = relCount.As<int>(),
types = types.As<List<string>>(),
});