Recursive parent/child categories

Recursive parent/child categories


I have spent a few days trying to figure out a way to recursively search a category entity having parent and child identifiers; below is a sample (ID - Category - Parent ID)

  • 12 - Access and Security - 0
  • 11 - Controller - 12
  • 13 - Peripherals - 12
  • 14 - Cards - 13
  • 28 - Child of Cards - 14
  • 15 - Proximity - 14
  • 29 - Child of Child of Cards - 28

For clarification, I can create a basic recursive search, however, it is limited to the depth of parent/child relationships (per the screenshot).

My objective, have a recursive search that is not limited to how deep the parent/child relationship goes and starts with a simple text search and find all branches of parent/child relationships based on the initial search.  The results, category IDs, will be used to join on another aggregate, items entity, yielding all items having a category found in the list.

You need to make your search for the child categories an action that takes the parent ids as a parameter.

Run the first query and call the action, if there are no results exit. If there are results, append them to a list and call the action again, this time with the parents being the results you just got.