Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9221887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:40:51+00:00 2026-06-18T03:40:51+00:00

I am having difficulties solving this problem using RavenDB. I have these classes. I

  • 0

I am having difficulties solving this problem using RavenDB. I have these classes.
I excluded a lot of properties from them to keep the example simple.

public class Menu
{
    public string Name { get; set; }
    public List<NavigationNode> Nodes { get; set; }
}

public class NavigationNode
{
    public string Text { get; set; }
    public Guid? PageId { get; set; }
    public string NodeType { get; set; }
    public List<NavigationNode> Nodes { get; set; }
}

public class Page
{
    public Guid PageId { get; set; }
    public string Slug { get; set; }
}

So as you can see this is about rendering a navigation menu. Node lists are hierarchical and can go deep, in theory infinitely(of course in reality 2-4 sub levels only). At first i stored the Slug in the Node but realised that, what happens if the page Slug changes, changing all nodes when a page changes slug i would have to loop through all menus, climb down the hierarchy and find all those Slug values to change them, which does not sound like an optimal solution.

So i was thinking it should be possible to build an index that combines the Page Slug with rest of the data from the Node in a hierarchical structure.

I have been reading about Map Reduce, Multimap and recurse but i am not even sure where to start.

I found this http://ravendb.net/docs/2.0/client-api/querying/static-indexes/indexing-hierarchies

Here is a simple example i tried just to get something started, and i cannot even get that to work since i really don’t understand the example on the page i linked to above.

  public class NavigationIndex : AbstractIndexCreationTask<Menu>
   {
        public NavigationIndex()
        {
            Map = menus => from menu in menus
                           from node in Recurse(menu, x => x.Nodes)
                           select new
                                      {
                                          WhatIsThis = node // <- Why is this a collection?
                                      };
        }
    }

According to the example node should not be a collection but an actual NavigationNode object.

Is it possible to achieve what i want in RavenDB and what am i doing wrong in the example?

Please feel free to ask anything you find confusing.

I apologize for the confusion. I’ll try to explain it.

EDIT:

Changing PageId to string will not be a problem. I am using Guids since i need to be able to generate primary key ID:s before inserting. Anyway, what i want to Query for from the index is a hiearachical tree of navigation links where the Pages Slug is included. So i can recursively loop out a navigation menu on the website.

Answers to Matt Johnson’s questions:

  1. I want a output of a class you can see below
  2. Page is a separate document
  3. I am only going to query by Menu Name

    public class NavigationIndexItem{
    public string MenuName { get; set; }
    public string Text { get; set; }
    public string Slug { get; set; }
    public string NodeType { get; set; }
    public List ChildItems { get; set; }
    }

Now when i see the above class i think i might a bit on the wrong path.

But anyway i will make some minor changes and thank you Matt for answering. However i am still running into same problem as before.

This row in your example: where node.PageId != null

node is not an instance of a specific NavigationNode but yet another collection so i cannot check the PageId property on it. I only get a list of LINQ extensions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:40:52+00:00Added an answer on June 18, 2026 at 3:40 am

    I’m making some assumptions of what you want. See my comments on the original question. But I think this is what you are after.

    First – you need to change the id of the Page class to Id instead of PageId. This is so Raven will use your guid as part of its document id. Really you would be better off with string Ids, but this will still work.

    Then you can do the following:

    public class NavigationIndex : AbstractIndexCreationTask<Menu>
    {
        public NavigationIndex()
        {
            Map = menus => from menu in menus
                           from node in Recurse(menu, x => x.Nodes)
                           where node.PageId != null
                           let page = LoadDocument<Page>("pages/" + node.PageId)
                           select new
                           {
                               menu.Name,
                               node.Text,
                               node.PageId,
                               page.Slug
                           };
        }
    }
    

    This uses the new LoadDocument feature of RavenDB 2.0, which is much more suitable than multi-map for your scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having difficulties in retrieving 50 results from google. I'm using this: public
I am having difficulties in disabling href links through jquery. I am using this
Im having difficulties creating a query. I have googled a lot but did not
I'm having difficulties parsing a string. This is the structure I have: Title:Avatar,Year:2009,Rated:PG-13,Released:18 Dec
I'm having difficulties with using internal imports inside my projects. This is a partial
I am having difficulties wrapping my head around this. I have a MyCollectionViewController class
I'm having difficulties reading an app.config using the ConfigurationManager. I have a custom section,
I having difficulties setting my footer properly. I have a Bottom navigation bar as
I am having difficulties using the ColorMatrixColorFilter to modify the color pixels in a
I'm having difficulties removing the lineStyle lines in JTrees using Netbeans. In a standalone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.