0
votes

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;
1
Hi @bech, what are you actually wanting to return? From first glance, your query in neo4jclient is not the same as the one you say works - as you're using optional matching and where. What is the output you want? - Is it one e2 object and mutiple e3s?Charlotte Skardon
Hi @Chris. Yep, I want any e2 I can reach directly from e, and then every e3 I can reach from any e2 that I find.bech
I figured it out I think. Updated the question to reflect so. Thanks for the help anyway Chris.bech

1 Answers

1
votes

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;