Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lack of Collect Method #484

Open
DOsterholz opened this issue Nov 12, 2024 · 2 comments
Open

Lack of Collect Method #484

DOsterholz opened this issue Nov 12, 2024 · 2 comments
Assignees
Labels

Comments

@DOsterholz
Copy link

Describe the bug
I am currently looking for a method like Collect. Unfortunately, I can't find it. The only possibility I have found so far is to use the collect functionality of the cypher via a raw string. Am I missing the method or does it really not exist?

Versions:

  • Neo4jClient 5.1.17
  • Bolt or Http BoltGraphClient
  • .NET Version .NET 8
  • Server Version 5.24.0

To Reproduce

[HttpGet("product-detail")]
public async Task<IActionResult> GetProductDetailsNeo4J(string productId, string language = "en")
{
    var result = await _neo4jClient.Cypher
        .Match("(p:Product {Id: $productId})-[:HAS]->(pv:ProductValue)-[:BELONGS_TO]->(a:Attribute)")
        .OptionalMatch("(pv)-[:TRANSLATED]->(vt:ValueTranslation)")
        .WithParam("productId", productId)
        .WithParam("language", language)
        .Return(() => new
        {
            de = Return.As<string>("p.De"),
            en = Return.As<string>("p.En"),
            properties = Return.As<List<Dictionary<string, object>>>(
                "COLLECT({ attributeName: CASE $language WHEN 'en' THEN a.En ELSE a.De END, " +
                "value: CASE $language WHEN 'en' THEN vt.En ELSE vt.De END })"
            )
        })
        .ResultsAsync;

    if (result == null || !result.Any())
    {
        return NotFound($"Product with ID {productId} not found.");
    }

    return Ok(result.First());
}

Expected behaviour
I thought there might be a “.Collect” C# method.

Additional context
The implementation is realized within an ASP Core application in a controller.

@Clooney24
Copy link
Contributor

From my point of view, this wouldn't be helpful, as COLLECT usually is used as an aggregate function besides other variables within WITH- or RETURN-Clauses. This could not be solved with a .Collect method.

@cskardon
Copy link
Member

What would you expect the code to look like with a Collect method? i.e. can you give a 'this is what I want' example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants