返回与Neo4jClient没有特定关系的节点

时间:2014-09-05 08:46:29

标签: neo4j neo4jclient

我正在使用Neo4jClient在.NET中开发一个社交照片应用程序来与Neo4j图形数据库交谈。我希望获得特定用户尚未看到的所有照片,我可以通过密码查询完成:

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;

不幸我不知道如何正确地将其转换为Neo4jClient。我尝试了下面的查询,但它没有按预期工作,它返回用户2已经看到的照片:

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 个答案:

答案 0 :(得分:1)

如果您查看了.OptionalMatch声明,我认为您需要更改它:

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

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