Search code examples
neo4jcypherneo4jclient

Neo4jClient: Delete a relationship


I have the following cypher query:

start n=node(0)
match (n)-[:USER_BELONGS_TO]-(x)-[r]->(y)
where (x.EmailAddress = 'someoneelse@something.net')
and (y.EmailAddress = 'someone@something.net')
and (type(r) = 'FOLLOWS')
delete r;

How do I get Neo4jClient to do the same thing? (and give me an indication that the query has succeeded or failed)

I was thinking something like this:

var results = new CypherFluentQuery(_dataOperations.GraphClient)
                  .Start("n", _dataOperations.GraphClient.RootNode)
                  .Match(string.Format("(n)-[:{0}]-(x)-[r]->(y)", UserBelongsTo.TypeKey))
                  .Where(string.Format("x.EmailAddress! ='{0}'", follower))
                  .And()
                  .Where(string.Format("y.EmailAddress! ='{0}'", leader))
                  .And()
                  .Where(string.Format("type(r) = '{0}'", Follows.TypeKey))
                  .Delete("r")
                  .Results;

However Delete() does not work in that context.

If I could get a RelationshipReference then I could call the method

void DeleteRelationship(RelationshipReference reference);

but I don't know if you can get a RelationshipReference via cypher and when I try a query like the following.

 var results = new CypherFluentQuery(_dataOperations.GraphClient)
              .Start("n", _dataOperations.GraphClient.RootNode)
              .Match(string.Format("(n)-[:{0}]-(x)-[r]->(y)", UserBelongsTo.TypeKey))
              .Where(string.Format("x.EmailAddress! ='{0}'", follower))
              .And()
              .Where(string.Format("y.EmailAddress! ='{0}'", leader))
              .And()
              .Where(string.Format("type(r) = '{0}'", Follows.TypeKey))
              .Return<RelationshipReference<Follows>>("r")
              .Results
              .SingleOrDefault();

I get the following "No parameterless constructor defined for this object" when the deserialization is taking place inside Neo4jClient. Anyway I would like to do this all in one query, not two.


Solution

  • This issue has now been fixed. You can now add a Delete clause after a Where.