到目前为止,我还不喜欢NEO4J客户端,但是我无法在NEO4JClient中看到这个Cypher查询,我看不到任何相同的例子:
match (e:CRMEntity)-[:LINKED_BY_USER]->(e2)-[:IS_SAME_AS*]-(e3)
RETURN e2, e3
这适用于Cypher,从CRMEntity到LINKED_BY_USER返回e2,以及我可以从e2到达的所有e3。
我似乎无法在NEO4JClient api中表达这一点。这就是我所拥有的:
var results = client.Cypher
.Match("(e:CRMEntity)-[:LINKED_BY_USER]->(e2)")
.OptionalMatch("(e2)-[:IS_SAME_AS*]-(e3)")
.Where((EntityGraphObject e) => e.Id == entity.Id)
.ReturnDistinct(e3 => new
{
GraphObject = e3.As<EntityGraphObject>(),
Type = e3.Labels()
})
.Results;
我可以看到,也许你可以创建一个新的自定义对象并将e2和e3放在其中,但这看起来有点愚蠢,因为每个e2都有多个e3结果。
这是唯一的方式还是有一些语法我没有得到?而Cypher和NEO4JClient相当新,所以我可能会遗漏一些简单的东西。感谢。
更新: 我想我明白了。我需要的是关于第二种关系的* 0 ..就像这样:
var inferredLinks = client.Cypher
.Match("(e:CRMEntity {Id: {EntityId}})-[:LINKED_BY_USER]->()-[:IS_SAME_AS*0..]-(e3)")
.WithParam("EntityId", entity.Id)
.ReturnDistinct(e3 => new
{
GraphObject = e3.As<EntityGraphObject>(),
Type = e3.Labels()
})
.Results;
答案 0 :(得分:1)
更新:我想我弄明白了。我需要的是关于第二种关系的* 0 ..就像这样:
var inferredLinks = client.Cypher
.Match("(e:CRMEntity {Id: {EntityId}})-[:LINKED_BY_USER]->()-[:IS_SAME_AS*0..]-(e3)")
.WithParam("EntityId", entity.Id)
.ReturnDistinct(e3 => new
{
GraphObject = e3.As<EntityGraphObject>(),
Type = e3.Labels()
})
.Results;