簡體   English   中英

如何使用C#Neo4jClient在兩個節點之間創建關系?

[英]How do I create a relationship between two nodes using C# Neo4jClient?

我是Neo4j場景的新手,但是當嘗試在播放列表和歌曲之間建立關系時,出現以下C#錯誤:

An unhandled exception of type 'System.NullReferenceException' occurred in Neo4jClient.dll

Additional information: Object reference not set to an instance of an object.

C#代碼:

client.Cypher
    .Match("(song1:Song)", "(playlist1:Playlist)")
    .Where((Song song1) => song1.Name == newSong.Name)
    .AndWhere((Playlist playlist1) => playlist1.Name == newPlaylist.Name)
    .Create("(playlist1)-[r:CONTAINS_SONG]->(song1)")
    .ExecuteWithoutResults();

對象newSongnewPlaylist用文件中的數據作為種子,並且已經存在於Neo4j數據庫中。 使用實時調試器時,我看到newSong.Name等於“ Goodbye In Her Eyes”,而newPlaylist.Name等於“ Adam Country”。 這些值都存在於Neo4j數據庫中(如下)。 使用.Query.QueryText產生相同的錯誤。 我正在使用neo4j-community-3.0.0-M03Neo4jClient 1.1.0.28

我創建了自己的查詢,但是可以感覺到C#代碼與正在輸出的實際查詢之間存在脫節。 以下作品:

MATCH (song1:Song),(playlist1:Playlist)
WHERE song1.Name = 'Goodbye In Her Eyes' AND playlist1.Name = 'Adam Country'
CREATE (playlist1)-[r:CONTAINS_SONG]->(song1)

Neo4j瀏覽器文本輸出:

+==============================+
|n                             |
+==============================+
|FullName: Adam Country.txt    |
|Name: Adam Country            |
+------------------------------+
|Artist: Zac Brown Band        |
|FullName: Goodbye In Her Eyes |
|Name: Goodbye In Her Eyes     |
+------------------------------+

我的C#代碼應如何實現這種關系?

[Playlist "Adam Country"] CONTAINS_SONG [Song "Goodbye In Her Eyes"]

如果將newSong和newPlaylist初始化,則最可能的解釋是未初始化客戶端。 您是否創建GraphClient的實例,然后調用Connect?

var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM