shaharnakash
shaharnakash

Reputation: 675

neo4jclient execute delete function not working

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; }
} 

Upvotes: 0

Views: 579

Answers (2)

Alastar Frost
Alastar Frost

Reputation: 1

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.

Upvotes: 0

Charlotte Skardon
Charlotte Skardon

Reputation: 6280

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.

Upvotes: 1

Related Questions