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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:07:52+00:00 2026-06-03T02:07:52+00:00

I was wondering if someone could help me understand RavenDB transformations as I cant

  • 0

I was wondering if someone could help me understand RavenDB transformations as I cant seem to get them working correctly. I tried following Ayende’s post but I am not able to apply it to my situation. I have two models, a UserModel and an UserAddressModel. The code is as follows

public class UserModel
    {
        #region Properties

        public string Id { get; set; }

        public string AccountId { get; set; }

        public string UserName { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Email { get; set; }

        public DateTime InsertDate { get; set; }

        #endregion 
    }

and

public class UserAddressModel
    {

        public string Id { get; set; }

        public string AccountId { get; set; }

        public string Address1 { get; set; }

        public string Address2 { get; set; }

        public string City { get; set; }

        public string State { get; set; }

        public string Zipcode { get; set; }

        public float Latitude { get; set; }

        public float Longitude { get; set; }

        public DateTime InsertDate { get; set; }

    }

I have my RavenDB Index set up like such.

public class UserDashboard_ByName : AbstractIndexCreationTask<UserModel>
    {
        public UserDashboard_ByName()
        {
            Map = users => from user in users
                                   select new { user.UserName, user.AccountId };

            TransformResults =
                (database, users) => from user in users
                                             let useraddress = database.Load<UserAddressModel>(user.AccountId)
                                             select new
                                                        { FirstName = user.FirstName,
                                                          LastName = user.LastName,
                                                          Address1 = useraddress.Address1,
                                                          Address2 = useraddress.Address2

                                                        };
        }
    }

and I am calling it with the following code

using (var session = DataDocumentStore.Instance.OpenSession())
            {

                //Get the AccountId
                var userDashboard =
                (from user in session.Query<UserModel, UserDashboard_ByName>()
                 where user.UserName == userName
                 select user).SingleOrDefault();


            }

When I call the index, it returns a UserModel type, not the anonymous type that I am expecting. Also, I do not understand how I can call

let useraddress = database.Load<UserAddressModel>(user.AccountId)

when there is no specific relationship that has been specified in code or anywhere else.

Maybe someone can explain to me how I should be joining data in RavenDB? Some expanded documentation or a nudge in the right direction to understanding this better would be greatly appreciated. Thanks in advance.

  • 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-03T02:07:53+00:00Added an answer on June 3, 2026 at 2:07 am

    The problem is inside your TransformResult function where you call database.Load<UserAddressModel>(user.AccountId). You can only load the UserAddressModel with its id, not by a property like AccountId.

    You have to store the id of the UserAddressModel inside your UserModel if you want to do it that way. However, I wouldn’t model it in that way. UserAddressModel doesn’t have any meaning on itself, so it should probably be part of UserModel. As a rule of thumb, you generally want to have your aggregrate roots as documents and everything else inside them.

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

Sidebar

Related Questions

I was wondering if someone could help me understand this problem. I prepared a
Just wondering if someone could help me with the following issue. On my local
I was wondering if someone could help me get pointers to solve this problem.
I'm trying to get started with HtmlAgilityPack and was wondering if someone could help
Just wondering if someone could help me with a very simple SQL query. I
I was wondering if someone could help me with this. I have defined my
Hey guys I was wondering if someone could provide a little help. I've been
was wondering if someone could help with this one. This is the first time
I was wondering if someone could help with an example criteria for nhibernate. I
I was wondering if someone could help me with a little issue I'm having.

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.