0
votes

I'm using the example from https://github.com/Readify/Neo4jClient/wiki/cypher-examples#delete-a-user-and-all-inbound-relationships

graphClient.Cypher
    .OptionalMatch("(user:User)<-[r]-()")
    .Where((User user) => user.Id == 123)
    .Delete("r, user")
    .ExecuteWithoutResults();

and change it to fit my needs to this

WebApiConfig.GraphClient.Cypher
    .OptionalMatch("(user:User)<-[r]-()")
    .Where((User user) => user.userId == userId)
    .Delete("r, user")
    .ExecuteWithoutResults();

but every time I can still get the user by

 User user1 = WebApiConfig.GraphClient.Cypher
        .Match("(u:User)")
        .Where((User u) => u.userId == userId)
        .Return(u => u.As<User>())
        .Results
        .FirstOrDefault();

what I'm doing wrong?

the Node labels is

User

the properties labels are

LastName, Name, FirstName, UpdatedTime, Email, facebookId, Picture, userId

the define of graph db class

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
           name: "ActionApi",
           routeTemplate: "api/{controller}/{action}/{id}",
           defaults: new { id = RouteParameter.Optional }
        );


        //Use an IoC container and register as a Singleton
        var url = ConfigurationManager.AppSettings["GraphDBUrl"];
        var user = ConfigurationManager.AppSettings["GraphDBUser"];
        var password = ConfigurationManager.AppSettings["GraphDBPassword"];
        var client = new GraphClient(new Uri(url), user, password);
        client.Connect();

        GraphClient = client;
    }

    public static IGraphClient GraphClient { get; private set; }
} 
2
Try to match your user and your relation first, and see the result, maybe your match clause is the problem. Also, can you please provide a data structure example?Supamiu
@supamiu did you main the node stracture?shaharnakash
I want to delete all relationship from and to this nodeshaharnakash
Could you please show us how "WebApiConfig.GraphClient" looks like?MicTech
my neo4j version is 2.0.1shaharnakash

2 Answers

1
votes

Have you tried:

graphClient.Cypher
    .Match("(user:User)")
    .OptionalMatch("(user)-[r]-()")
    .Where((User user) => user.Id == 123)
    .Delete("r, user")
    .ExecuteWithoutResults();

I imagine your user has outbound relationships, so won't be deleted as 'r' was only inbound.

0
votes

This is quite old, but here is one current hint:

Use DetachDelete method instead of Delete. Then the relationships are automatically deleted without the need to search for them first.