Return a node collection with relationship properties

I want to get a node (A) with a relationship (R) and multiple nodes (B)

Relationship (R) have the property number.

And i want a query to return node (A) with multiple node (B) and for each node (B) return also the property number.

without 'number' property i was doing this:

 MATCH (a: Node)-[r]-(b: Node)
WHERE type(r) = 'MADE_OFF' AND a.id = 'randomId'
RETURN a, collect(b)

If I return 'a, collect(b), r' relationship data is unrelated to node (B)

Any suggestions?

Thanks!

Hello @danielbahe :slight_smile:

Can you write an example of what you would like to get as result?

Regards,
Cobra

I'm mapping the result to .Net entities with Neo4jMapper
I want to have
EntityB: that correspond with Node (B)
EntityB should have node(B) properties and the number property from the relationship

Thanks for help!

We need to know the format (a string, a list, etc.) :slight_smile:

Can you show what return the current query and what you would like to get?

Currently I'm doing this on C#

public async Task<Result<Recipe>> GetById(Guid id)
        {
            var recipeId = id.ToString();
            var session = GetStartedSession();
            var result = await session.RunAsync(@"
                        MATCH (r:Recipe)-[c]-(i:Ingredient)
                        WHERE type(c) = 'MADE_OFF' AND r.id = $recipeId
                        RETURN r,collect(i)
                        ", new { recipeId });
            var recipe = (await result.ToListAsync()).Map((Recipe r, List<Ingredient> i) => new Recipe
            {
                Name = r.Name,
                Id = r.Id,
                Ingredients = new List<Ingredient>(i)
            });

            return Result.Success(recipe.FirstOrDefault());
        }

And I get this response

The "MADE_OFF" relationship have a integer value named quantity. And I want to include the quantity value in the correct ingredient (only in the C# model)

I guess there are some cypher tricks to do that but I'm still trying.
Of course is possible with C# but I think that is better include this "logic" on the query than do it in memory on my app.

Thanks!

MATCH (a:Recipe{id:'randomId'})-[r:MADE_OFF]-(b:Ingredient)
WITH a, b, r.quantity AS quantity
RETURN a, collect(b{.*, quantity})