Mike Barnes
Mike Barnes

Reputation: 4305

Cypher Query Issues Neo4j C# Client

I am getting an error on the following code that says:

enter image description here

Here is the code, I need this method to return the Max Value? is it an IEnumerable or an 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;
        }

Here is the query I would like to perform:

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

Upvotes: 0

Views: 1037

Answers (3)

Mike Barnes
Mike Barnes

Reputation: 4305

No errors are thrown when I made these changes to the method after reading 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;
    }

Upvotes: 0

Wesam Nabki
Wesam Nabki

Reputation: 2614

You should so the following:

// 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();

    }

Upvotes: 0

Tatham Oddie
Tatham Oddie

Reputation: 4290

You want this:

public int GraphGetMaxVersion(IEnumerable<NodeReference<VersionNode>> nodes)
{
    return graphClient.Cypher
        .Start(new { n = nodes })
        .Return(() => Return.As<int>("max(n.Version)"))
        .Results
        .Single();
}
  1. I haven't tested that. I just bashed it out here in the textbox, but it should work.
  2. If you don't need to return a complex type, don't. That is, turn Return(() => new { Foo = All.Count() }) into Return(() => All.Count()).
  3. If you don't need to use an identity in your return lambda, don't pass it in. That is, this argument is pointless: Return((somePointlessIdentityHere) => All.Count())
  4. Use either Neo4jClient 1.0.0.570 or above, or change .Start(new { n = nodes }) to .Start(new { n = nodes.ToArray() }).

Upvotes: 1

Related Questions