1

I am developing a social photo app in .NET using Neo4jClient to talk to a Neo4j graph database. I want to get all photos which a specific user hasn't already seen which I can accomplished with the cypher query:

MATCH (user:User)-[:USER_PHOTO]-(photo:Photo) 
OPTIONAL MATCH (photo)-[r:USER_SEEN_PHOTO]-(currentUser:User) 
WHERE (currentUser.Id = 'user2') 
WITH photo,user, count(currentUser) AS cnt 
WHERE cnt = 0 
RETURN DISTINCT photo, user;

Unfortunalety I don't know how to correctly translate this to Neo4jClient. I tried below query but it doesn't work as expected and it's returning photos user2 already seen:

var graphResults = await graphClient.Cypher
            .Match("(user:User)-[:USER_PHOTO]->(photo:Photo)")
            .OptionalMatch("user-[:USER_SEEN_PHOTO]-(currentUser:User)")
            .Where((UserEntity currentUser) => currentUser.Id == currentUserId)
            .With("user, photo, count(currentUser) AS cnt")
            .Where("cnt = 0")
            .ReturnDistinct((photo, user) => new
            {
                Photo = photo.As<PhotoEntity>(),
                User = user.As<UserEntity>()
            }).ResultsAsync;

1 Answer 1

1

If you have a look at your .OptionalMatch statement, I think you need to change it from:

.OptionalMatch("user-[:USER_SEEN_PHOTO]-(currentUser:User)")

to

.OptionalMatch("photo-[:USER_SEEN_PHOTO]-(currentUser:User)")
                 ^^^
1
  • Ooops, I feel embarrassed now, what a silly mistake :) I was so focused on that Neo4jClient couldn´t handle count in the WITH-clause so I obviously got blinded. Thanks for opening my eyes Chris!! Sep 5, 2014 at 10:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.