如何使用参数数组进行 Neo4jClient 查询?

How make a Neo4jClient query with an array of params?

原始 Cypher 中:

    MATCH (user)
    WHERE user.name IN ['Joe', 'John', 'Sara', 'Maria', 'Steve'] 
    RETURN user

类似于:

    public Nodes Parse(string[] Str)
    {
        Nodes res = graphClient.Cypher.OptionalMatch("(a)-[]->(b)")    
        .Where((Vertex a) => a.Name == Parallel.ForEach<string>(Str, (s) =>  return s))   //NOT WORK! return is illegal
        .Return((a, b) => new Nodes { Source = a.As<Vertex>(), Peers = b.CollectAs<Vertex>().ToList() })
        .Results.FirstOrDefault();
        return res;
    }

当 Neo4jClient 的完整文档可用时?)

要更改您的代码,您可以这样做:

public Nodes Parse(string[] str)
{
    var query = graphClient.Cypher
        .Match("(a)-[]-?(b)")
        .Where("a.Name IN $namesParam")
        .WithParam("namesParam", str)
        .Return((a,b) => new Nodes {
            Source = a.As<Vertex>(),
            Peers = b.CollectAs<Vertex>()
        });
    var result = query.Results.FirstOrDefault();
    return result;
}

要执行您在顶部的查询,您需要执行以下操作:

var names = new [] {"Joe", "John", "Sara", "Maria", "Steve"};
var users = graphClient
    .Match("(user)")
    .Where("user.name IN $names")
    .WithParam("names", names)
    .Return(user => user.As<User>())
    .Results;

恐怕永远不会有完整的客户文档,除非其他人愿意贡献。

  var names = new [] {"Joe", "John", "Sara", "Maria", "Steve"};
  var users = graphClient
      .Unwind(names, "name")
      .Match("(user)")
      .Where("user.name = name")          
      .Return(user => user.As<User>())
      .Results;