2014-09-01 117 views
1

我試圖以編程方式將信息保存到使用Neo4Jclient的Neo4J DB中。無法使用Neo4Jclient創建項目

我一直在試圖遵循這些例子,但它似乎並沒有工作。

我創建這似乎工作數據庫連接,但我的代碼不會因以下行編譯..

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」。

我在做什麼錯?

+0

你可以把代碼放在上面嗎?即什麼是「孩子」對象? – 2014-09-02 07:20:02

+0

我剛剛開始使用void方法,除此之外唯一的方法簽名是接受定義爲child的sting值。但我補充說當時我在那裏 – Nav 2014-09-02 15:01:20

回答

2

我想我明白你在做什麼,假設child存在,你需要做一些改變。 首先,你需要使用WithParamWithParams,之後,把它進入DB你需要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(); 

一般來說,如果你有很多的參數在一個查詢是非常有用的,這一切無論歸結爲同一個。