如何使用neo4jclient中的unwind更新数据? [英] how to use unwind in neo4jclient for updating data?

查看:671
本文介绍了如何使用neo4jclient中的unwind更新数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新neo4j数据库中的某些记录.为了使我在C#中的Neo4jClient中编写此查询:

I want to update some of my records in the neo4j DB. In order that I wrote this query in Neo4jClient in C#:

 _client.Cypher
            .Unwind(skills, "updatedSkill")
            .Match("(s : Skill {Name: updatedSkill.Name}")
            .Set("s = updatedSkill");
            .ExecuteWithoutResults();

技能是技能"对象的简单列表:

Where skills is a simple list of Skill objects:

    public class Skill
        {
            public string Name { get; set; }
            public string Phrase { get; set; }          
        }

但是当我调用该代码时,它将引发异常.其翻译后的Cypher查询为:

But this code throws exception when I call it. Its translated Cypher query is:

UNWIND [{
    "Name": "name1",
    "Phrase": "phrase1",
},{
    "Name": "name2",
    "Phrase": "phrase2",
}] AS updatedSkill
MATCH (s : Skill {Name: updatedSkill.Name}
SET s = updatedSkill

例外情况如下:

     Invalid input '"': expected whitespace, comment, an identifier,
 UnsignedDecimalInteger, a property key name or '}' (line 3, column 5 (offset: 17))
    "    "Name": "name1","
         ^

当我删除名称"和短语"属性的双引号时,查询将正确运行.但是我可以这样做,因为查询是由Neo4jClient自动生成的.

When I remove the double-quotes of the properties Name and Phrase the query runs correctly. But I can do it because the query is auto-generated by Neo4jClient.

有什么想法吗?

推荐答案

您的MATCH语句中有错字.它缺少结尾).如果您对此进行更正,则您的查询应该可以正常工作.顺便说一句,在SET语句的末尾还有一个多余的分号,我已经删除了.

You have a typo in your MATCH statement. It is missing the closing ). If you correct this your query should work as expected. As an aside there is also an extra semi-colon at the end of your SET statement, which I have removed.

_client.Cypher
        .Unwind(skills, "updatedSkill")
        .Match("(s:Skill {Name: updatedSkill.Name})")
        .Set("s = updatedSkill")
        .ExecuteWithoutResults();

顺便说一句,这是一个示例,其中您正在查看的查询并不真正代表发送到Neo4j REST API的参数化查询.我认为您是通过查看_cypher.Query.DebugQueryText获得的?在大多数情况下,这很好,但是在传递JSON对象的地方,由于它处理参数对象的字符串表示形式的方式,可能导致误导性查询.如果您查看Neo4jClient抛出的实际异常,则应该通知您问题的真正原因.在这种情况下

As an aside, this is an example where the query you are looking at it not truly representative of the parameterized query being sent to the Neo4j REST API. I assume that you obtained it by looking at _cypher.Query.DebugQueryText? For most situations this is just fine but where you are passing JSON objects it can lead to a misleading query due to the way it manipulates the string representations of the parameter objects. If you look at the actual exception being thrown by Neo4jClient it should inform you of the real cause of the issue. In this case

SyntaxException:输入'S'无效:预期的空格,注释,')'或关系模式... "SET s = UpdatedSkill"
  ^

SyntaxException: Invalid input 'S': expected whitespace, comment, ')' or a relationship pattern... "SET s = updatedSkill"
 ^

这告诉您真正的问题是,在启动SET语句之前尚未关闭MATCH语句.

This tells you the real problem is that you have not closed off your MATCH statement before starting the SET statement.

这篇关于如何使用neo4jclient中的unwind更新数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆