2014-09-05 94 views
1

我正在開發一個使用Neo4jClient與Neo4j圖形數據庫交談的.NET社交照片應用程序。我想這一個特定的用戶尚未看到所有的照片,我可以用暗號查詢完成:與Neo4jClient沒有特定關係的返回節點

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我不知道如何正確地翻譯這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

如果你看一下你的.OptionalMatch發言,我想你需要從改變:

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

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

哎呀,我現在覺得尷尬,多麼愚蠢的錯誤:)我是如此專注於WITH子句所以我顯然得到了矇蔽在Neo4jClient couldn't句柄計數。謝謝你打開我的眼睛克里斯! – 2014-09-05 10:24:17

+0

我們都做到了:) – 2014-09-05 14:19:40

相關問題