我是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();
对象newSong
和newPlaylist
用来自文件的数据播种,并且已存在于Neo4j数据库中。使用实时调试器时,我看到newSong.Name
等于“在她眼中再见”,newPlaylist.Name
等于“Adam Country”。这些值都存在于Neo4j数据库中(如下)。使用.Query.QueryText
也会产生相同的错误。我正在使用neo4j-community-3.0.0-M03
和Neo4jClient 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"]
答案 0 :(得分:1)
如果初始化newSong和newPlaylist,最可能的解释是客户端未初始化。 您是否创建了GraphClient实例,然后调用Connect?
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();