Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-16-2020 06:56 AM
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!
Solved! Go to Solution.
08-16-2020 08:41 AM
MATCH (a:Recipe{id:'randomId'})-[r:MADE_OFF]-(b:Ingredient)
WITH a, b, r.quantity AS quantity
RETURN a, collect(b{.*, quantity})
08-16-2020 07:05 AM
08-16-2020 07:44 AM
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!
08-16-2020 07:49 AM
We need to know the format (a string, a list, etc.)
Can you show what return the current query and what you would like to get?
08-16-2020 08:26 AM
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!
08-16-2020 08:41 AM
MATCH (a:Recipe{id:'randomId'})-[r:MADE_OFF]-(b:Ingredient)
WITH a, b, r.quantity AS quantity
RETURN a, collect(b{.*, quantity})
All the sessions of the conference are now available online