Search code examples
c#.netneo4jgraph-databasesneo4jclient

Neo4j Client Match List Of Id's


I'm trying to create a query the finds records who id is in a list, so I don't have query the database multiple times. My query however is throwing an error. How can I fix this?

Query

    public static IEnumerable<Task> GetByIds(List<string> ids)
    {
        return DBUtils.DBService.Cypher
            .Match("(node:Task)")
            .Where((Task node) => ids.Contains(node.Id))
            .Return(node => node.As<Task>())
            .Results.ToList();
    }

Exception

SyntaxException: Invalid input 'n': expected whitespace, '.', node labels, '[', \"=~\", IN, STARTS, ENDS, CONTAINS, IS, '^', '*', '/', '%', '+', '-', '=', \"<>\", \"!=\", '<', '>', \"<=\", \">=\", AND, XOR, OR, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, RETURN, UNION, ';' or end of input (line 2, column 11 (offset: 33))\n\"WHERE {p0}node.Id\r\"\n           ^

Solution

  • Try it (Using IN instead of CONTAINS):

    public static IEnumerable<CareTask> GetByReferenceIds(List<string> ids)
    {
        return DBUtils.DBService.Cypher
            .Match("(node:Task)")
            .Where("node.Id IN {ids}")
            .WithParam("ids", ids)
            .Return(node => node.As<Task>())
            .Results.ToList();
    }