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 8768377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:03:04+00:00 2026-06-13T17:03:04+00:00

Using RavenDB within an ASP.NET MVC (4) application, what is the correct pattern for

  • 0

Using RavenDB within an ASP.NET MVC (4) application, what is the correct pattern for loading a set of related entities and passing them to a view?

Taking Stack Overflow as the canonical example, assume the following entities:

class User
{
    public int Id { get; set; }

    public string UserName { get; set; }
}

class Comment
{
    public int Id { get; set; }

    public string Body { get; set; }

    public string Author{ get; set; }
}

class Question
{
    public int Id { get; set; }
    // ...
    public List<Comment> Comments { get; set; }

    public Question()
    {
        Comments = new List<Comment>();
    }
}

What we want to do is display the users information next to the comments under the question, The comments are stored as part of the Question document, so we Include the Comment.Author

Our query might look like this:

var question = RavenSession.Include<Question>(x => x.Author)
                           .Include<Comment>(x => x.Author)
                           .Load<Question>(id);

Now we have the question object with all it’s comments, and the Raven client has cached all the user profiles we’ll need, What is the correct / best / most RavenDB approved way of pairing the User objects with the relevant Comments objects?

One thought is that I could transform the User and Comment into a CommentViewModel and send that down to the client, but that seems quite manual.

Another option could be to add another property to the Comment for Author, that is [JsonIgnore]‘d and in the getter, lazy load the user from the Raven session. This feels dirty because the Comment model object would need to hold a reference to the raven session.

  • 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-13T17:03:05+00:00Added an answer on June 13, 2026 at 5:03 pm

    You want to do it like this:

    var question = RavenSession.Include<Question>(x => x.Author)
                               .Include(x => x.Comments.Select(c=>c.Author))
                               .Load(id);
    

    This works for 1.2, note.
    Then you can just call Load(question.Author) to get the doc from the session cache.

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

Sidebar

Related Questions

I'm using ASP.NET MVC 3, with Raven DB as a backing data store. I
Using ASP.NET MVC there are situations (such as form submission) that may require a
I'm following along with the RavenDB on Tekpub talking about using it with ASP.NET
I'm using ravendb as storage backend. Since it uses unit of work pattern I
I am thinking/evaluating of using RavenDB for the enterprise application our company is planning
I'm starting a web app that will be using asp.net membership services (with a
I am trying to learn RavenDB and using it's .Net client. If I am
So I installed RavendDB on a Win2003 server using these instructions: http://old.ravendb.net/documentation/docs-deployment-iis And i
all... I'm using RavenDB embedded, latest stable build using NuGet and MVC 3. public
I am using ravendb 1.0.531 in an MVC 3 app to store my data.

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.