Search code examples
c#asp.net-coreneo4jneo4jclient

Conversion Neo4j query to .Net


I'm using Neo4jClient to connect my Aspnet Application with Neo4j database. But I'm having trouble when i try to convert this query:

MATCH (person:Person)-[r_students]->(students:Person)
 where person.personID = '{0}'
 return students, r_students;

to this code:

_client.Cypher
            .Match("(person:Person)-[r_students]->(students:Person)")
            .Where(string.Format(@"person.personID = '{0}'", id))
            .Return((students, r_students, person) => new TeacherStudents
            {
                Students = students.As<Person>(),
                StudentsRelations = r_students.As<Supervised>(),
            })
            .Results;

the error I'm getting is:

FormatException: Input string was not in a correct format.

The entire contents of the error (it's very long) can be found here

Neo4j Error

How can I convert properly?


Solution

  • I would suggest you to try this Cypher:

    graphClient.Cypher
        .Match("(person:Person)-[r_students]->(students:Person)")
        .Where("person.PersonID = {id}")
        .WithParam("id", id)
        .Return((students, r_students, person) => new TeacherStudents
        {
           Student = students.As<Person>(),
           StudentsRel = r_students.As<Supervised>(),
        })
        .Results;
    

    Tell me if its doin the job.