2013-05-08 29 views
0

我在下面的代碼,說得到一個錯誤:的Cypher查詢問題Neo4j的C#客戶

enter image description here

下面是代碼,我需要這個方法返回的最大值?它是一個IEnumerable或int?

public IEnumerable<int> GraphGetMaxVersion(IEnumerable<Node<VersionNode>> nodeId) 
     { 
      IEnumerable<int> nodes = null; 

      clientConnection = graphOperations.GraphGetConnection(); 

       var query = clientConnection 
        .Cypher 
        .Start(new 
        { 
         n = nodeId 
        }) 
        .Return((maxVersion) => new 
        { 
         MaxVersion = Return.As<int>("max.Version") 
        }); 
       nodes = query.Results; 

      return nodes; 
     } 

這裏是我想執行查詢:

START n=node(2,3,4) 
RETURN max(n.property) 

回答

1

希望此之後做出這些改變的方法不會引發任何錯誤:

public int GraphGetMaxVersion(IEnumerable<NodeReference<VersionNode>> nodes) 
{ 
    return graphClient.Cypher 
     .Start(new { n = nodes }) 
     .Return(() => Return.As<int>("max(n.Version)")) 
     .Results 
     .Single(); 
} 
  1. 我還沒有測試過。我只是在文本框中把它弄糊塗了,但它應該可以工作。
  2. 如果您不需要返回複雜類型,則不要。也就是說,將Return(() => new { Foo = All.Count() })轉換爲Return(() => All.Count())。 。
  3. 如果你不需要在你的回報拉姆達使用一個身份,不通過它就是說,這種說法是沒有意義的:Return((somePointlessIdentityHere) => All.Count())
  4. 二者必選其一Neo4jClient 1.0.0.570或以上,或更改.Start(new { n = nodes }).Start(new { n = nodes.ToArray() })
0

,當我讀this post.

public int GraphGetMaxVersion(int nodeId) 
    { 
     int nodes = 0; 

     clientConnection = graphOperations.GraphGetConnection(); 

      var query = clientConnection 
       .Cypher 
       .Start(new 
       { 
        n = nodeId 
       }) 
       .Return((maxVersion) => new 
       { 
        MaxVersion = Return.As<int>("max(n.Version)") 
       }) 
       .Results 
       .Single(); 
      nodes = query.MaxVersion; 

     return nodes; 
    } 
0

你應該這麼以下幾點:

// Return Max follwoer node ID: 
    public float ReturnMaxFollowerID(IGraphClient Client) 
    { 
     return Client.Cypher 
      .Match("(n:User)") 
      .Return(() => Return.As<float>("max(n.userID)")) 
      .Results 
      .Single(); 

    }