Reputation: 791
I'm new to the Neo4j scene, but when attempting to create a relationship between a playlist and a song I get the following C# error:
An unhandled exception of type 'System.NullReferenceException' occurred in Neo4jClient.dll
Additional information: Object reference not set to an instance of an object.
C# Code:
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();
Objects newSong
and newPlaylist
are seeded with data from a file and already exist in the Neo4j database. When using the live debugger I see newSong.Name
is equal to "Goodbye In Her Eyes" and newPlaylist.Name
is equal to "Adam Country". These values both exist in the Neo4j database (below). Using .Query.QueryText
gives the same error as well. I'm using neo4j-community-3.0.0-M03
and Neo4jClient 1.1.0.28
.
I've created my own query that works, but I feel like there is a disconnect between the C# code and the actual query that is being output. The following works:
MATCH (song1:Song),(playlist1:Playlist)
WHERE song1.Name = 'Goodbye In Her Eyes' AND playlist1.Name = 'Adam Country'
CREATE (playlist1)-[r:CONTAINS_SONG]->(song1)
Neo4j Browser Text Output:
+==============================+
|n |
+==============================+
|FullName: Adam Country.txt |
|Name: Adam Country |
+------------------------------+
|Artist: Zac Brown Band |
|FullName: Goodbye In Her Eyes |
|Name: Goodbye In Her Eyes |
+------------------------------+
What should my C# code look like to accomplish this relationship?
[Playlist "Adam Country"] CONTAINS_SONG [Song "Goodbye In Her Eyes"]
Upvotes: 0
Views: 704
Reputation: 1911
If newSong and newPlaylist are initialised the most likely explanation is that the Client is not initialised. Do you create an instance of GraphClient and then call Connect?
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
Upvotes: 1