I'm liking the NEO4J Client so far, but I can't see to formulate this Cypher query in the NEO4JClient, and I can't see any examples that are the same:
match (e:CRMEntity)-[:LINKED_BY_USER]->(e2)-[:IS_SAME_AS*]-(e3)
RETURN e2, e3
This works in Cypher, returning e2 as related from a CRMEntity through LINKED_BY_USER, as well as all e3's that I can reach from e2.
I can't quite seem to formulate that in the NEO4JClient api though. This is what I have:
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;
I can see that perhaps you could create a new custom object and put both e2 and e3 in that, but that seems kind of silly, given that there are multiple results for e3 for every e2.
Is that the only way or is there some syntax I'm not getting? Rather new to Cypher and NEO4JClient, so I might be missing something simple. Thanks.
UPDATE: I think I figured it out. What I needed was a *0.. on the second relationship like so:
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;
optional matching
andwhere
. What is the output you want? - Is it onee2
object and mutiplee3
s? – Charlotte Skardon