I am struggling to update my code that uses Neo4JClient v3.x to work with the latest Neo4J server and Neo4jClient v5.x.
my query basically will create 2 nodes and a relationship between them. if any node or both nodes does not exist, they will be created along the relationship
old working query:
query1 = client.Cypher
.Match("(e1:Entity)", "(e2:Entity)")
.Where("e1.Id={id1} and e2.Id={id2}")
.WithParam("id1", id1)
.WithParam("id2", id2)
.WithParam("line", line)
.Merge("(e1)-[r:REF {LINE:{line}}]->(e2)");
above code does not work in the new version of Neo4j server / Neo4jClient my attempt to modify it currently create duplicate nodes instead of unique ones
query1 = client.Cypher
.Create("(e1:Entity $id1)")
.Create("(e2:Entity $id2)")
.WithParam("id1",new { Id = id1 })
.WithParam("id2", new { Id = id2 })
.WithParam("line", line)
.Create("(e1)-[r:REF {LINE:$line}\]->(e2)");
can you help me convert the first query above to work in the newer version ?
Your first query does a
MATCHat the beginning, which would never haveCREATEde1ore2- you would need to useMERGEto achieve what you're after.This query:
should do what you actually want.
e1ande2would beCREATEd if they are not in the database, orMATCHed if they are in the database.EDIT: I noticed in your original query that you did in fact
MERGEthe relationship, so I've updated the code accordingly.