Working with multiple columns in Neo4jClient query results

I have a Neo4j database, which for the sake of simplicity contains user nodes and university nodes - where the User can be connected to the university through the relation [: STUDENT_AT].

I want to return the user data and university information for a specific user, in this case, a query by the value "username".

The request itself works fine, however, I cannot develop the correct method to get the deserializer in Neo4jClient to give me two objects to work with. Below I believe that this should work, but alas, this does not happen.

graph.Cypher .Start("user", "node(*)") .Match("user-[:STUDENT_AT]->university") .Where<User>(user => user.Username != null && user.Username.ToLower() == username.ToLower()) .Return((user, university) => new { User = user.As<User>(), University = university.As<University>() }) .Results; 

Where graph is IGraphClient successfully associated with Neo4j.

I get an error...

The response to the request contains the User, University columns, however <> f__AnonymousType0`2 [[XYZ.Entities.User, XYZ.Entities, Version = 1.0.0.0, Culture = Neutral, PublicKeyToken = null], [XYZ.Entities.University, XYZ.Entities, Version = 1.0.0.0, Culture = Neutral, PublicKeyToken = null]] does not contain publicly configured properties for receiving this data.

So, if anyone can provide me with a method to get objects from a cypher request that returns multiple columns using Neo4jClient, I would really appreciate it!

+4
source share
2 answers

Anonymous types work from 1.0.0.514 onwards.

Update, and the request specified in your question will work as it is written.

+1
source

The only way I was able to get it to work was to actually declare the type, which was the collection of several columns that I needed. For example, you would need to declare a dummy type that contains the User property and the university property. In your case, you can try:

 private class UserAndUniversity { public User User {get; set;} public University University {get; set;} } public object MyMethod() { graph.Cypher .Start("user", "node(*)") .Match("user-[:STUDENT_AT]->university") .Where<User>(user => user.Username != null && user.Username.ToLower() == username.ToLower()) .Return((user, university) => new UserAndUniversity { User = user.As<User>(), University = university.As<University>() }) .Results; } 

Note that property names in your dummy summary type are case sensitive; they must exactly match the names you use in the cypher RETURN clause.

It is clearly idiotic, but it is the only thing that worked for me; I tried everything from Tuples to the dynamic keyword.

+2
source

All Articles