【问题标题】:Can't create an item using the Neo4Jclient无法使用 Neo4Jclient 创建项目
【发布时间】:2014-09-02 23:03:02
【问题描述】:

我正在尝试使用 Neo4Jclient 以编程方式将信息保存到 Neo4J DB。

我一直在尝试按照示例进行操作,但似乎不起作用。

我创建了一个似乎可以工作的数据库连接,但是由于下面的行,我的代码无法编译..

public void SaveNewRootItem(string child)
    {
        client = new GraphClient(new Uri([ConnectionStringhere]));

        client.Connect();
            client.Cypher
            .Create("(m:LinkItem {child})")
            .WithParams("child", child);
    }

根据示例on the wiki for the opensource repo,我应该在“WithParams”中提供参数化信息。

我做错了什么?

【问题讨论】:

  • 你能把这个代码也放上去吗?即child 对象是什么?
  • 我刚开始使用 void 方法,除此之外唯一的就是方法签名,它接受定义为子项的字符串值。但我添加了当时我在哪里

标签: c# neo4jclient


【解决方案1】:

我想我明白你在做什么,假设 child 存在,你需要做一些改变。 首先,您需要使用WithParam 而不是WithParams,然后,要将其放入数据库中,您需要使用ExecuteWithoutResults(),因此您的查询将如下所示:

client.Cypher
    .Create("(m:LinkItem {child})")
    .WithParam("child", child)
    .ExecuteWithoutResults();

如果你确实想使用WithParams,你必须提供一个字典:

client.Cypher
    .Create("(m:XX {child})")
    .WithParams(new Dictionary<string, object>{{"child", child}})
    .ExecuteWithoutResults();

通常,如果您在一个查询中有很多参数,这将很有用,无论如何都归结为相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-20
    • 2020-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多