1
votes

I know how to dynamically create my MATCH and WHERE clauses, and in my situation it's unfortunately something I've got to do... SO, I have something like (and this is a contrived example):

var query = client
    .Cypher
    .Match("(u1:User)-[:LINKED]->(w:Web)","(u2:User)-[:LINKED]->(w:Web)","(u3:User)-[:LINKED]->(w:Web)")
    .Where("u1.User.Id = {u1Param}").WithParam("u1Param", 1)
    .AndWhere("u2.User.Id = {u2Param}").WithParam("u2Param", 2)
    .AndWhere("u3.User.Id = {u3Param}").WithParam("u3Param", 3);

The Match and Where are dynamically generated based on user input, and this generates the correct Cypher.

MATCH 
    (u1:User)-[:LINKED]->(w:Web),  (u2:User)-[:LINKED]->(w:Web),  (u3:User)-[:LINKED]->(w:Web)
WHERE 
    u1.User.Id = 1
    AND u2.User.Id = 2
    AND u3.User.Id = 3

On the server (in Cypher) I can do something like:

RETURN u1, u2, u3

and I'll get the 3 nodes I'm looking for. My problem is the general way of Returning data via the neo4jclient is via an Expression, so, to replicate I would do:

query.Return(
    (u1, u2, u3) => 
    { 
        U1 = u1.As<User>(), 
        U2 = u2.As<User>(), 
        U3 = u3.As<User>()
    });

I don't know that there will only be '3' responses, there could be many more, or indeed less. Any ideas on how to achieve this? Either as is, or in a totally different way, I'm open to all options.

I'd like to something like:

 query.Return<User>("u1", "u2", "u3"); //returning IEnumerable<User>

or maybe:

 query.Return<User>("u1").AndReturn("u2").AndReturn("u3"); 

I know I can revert for these queries to calling the db directly through HttpClient or some such, but I'd rather avoid that if I can. To be honest I'd be happy with parsing them all to dynamic, but that's not possible at present (or is it??? :)).

1

1 Answers

2
votes

Neo4jClient doesn't have any good solutions for dynamic return shapes like this.

In this contrived example at least, can you just flatten the nodes into a single list?

.Return<IEnumerable<User>>("[u1, u2, u3]")

You can easily tell which is which with the Id property that you're using in the WHERE clause but would also be available in C#.