Database Reference
In-Depth Information
Retrieving and Updating a Node
Once nodes have been added to the database, you will need a way to retrieve and modify them. Listing 7-2 shows the
process for finding a node by its node id value and for retrieving a node and updating it in the same query execution.
Listing 7-2. Retrieving and Updating a Node
var _graphClient = new GraphClient(new Uri("http://localhost:7474/db/data"));
// retrieve a user by their user.userId
User u = _graphClient.Cypher
.Match("(user:User)")
.Where<User>(user => user.userId == "10")
.Return(user => user.As<User>())
.Results.Single();
// update the user by their user.id
_graphClient.Cypher
.Match("(user:User)")
.Where<User>(user => user.userId == "10")
.Set("user.Business = { business }")
.WithParam("business ", "Graph Story")
.ExecuteWithoutResults();
Removing a Node
Once a node's graph id has been set and saved into the database, it becomes eligible to be removed when necessary.
In order to remove a node, a match can be made on a node object instance and then the node can be deleted in the
same query execution (Listing 7-3).
You cannot delete any node that is currently set as the start point or end point of any relationship. You must
remove the relationship before you can delete the node.
Note
Listing 7-3. Deleting a Node
var _graphClient = new GraphClient(new Uri("http://localhost:7474/db/data"));
// delete a user
_graphClient.Cypher
.Match("(user:User)")
.Where<User>(user => user.userId == "10")
.Delete("user")
.ExecuteWithoutResults();
// delete a user and its relationships
_graphClient.Cypher
.OptionalMatch("(user:User)<-[r]-()")
.Where<User>(user => user.userId == "10")
.Delete("r, user")
.ExecuteWithoutResults();
 
 
Search WWH ::




Custom Search