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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:59:33+00:00 2026-05-26T11:59:33+00:00

I have the following document called Reservation: { CustomerId: 1, Items: [ { EmployeeId:

  • 0

I have the following document called Reservation:

{
    "CustomerId": 1,
    "Items": [
        {
            "EmployeeId": "employees/1",
            "StartTime": "2011-08-15T07:20:00.0000000+03:00",
            "EndTime": "2011-08-15T07:40:00.0000000+03:00"
        },
        {
            "EmployeeId": "employees/1",
            "StartTime": "2011-08-15T07:40:00.0000000+03:00",
            "EndTime": "2011-08-15T09:10:00.0000000+03:00"
        },
        {
            "EmployeeId": "employees/3",
            "StartTime": "2011-08-16T07:20:00.0000000+03:00",
            "EndTime": "2011-08-16T11:35:00.0000000+03:00"
        }
    ]
    "ReservedAt": "2011-10-20T15:28:21.9941878+03:00"
}

In addition I have the following projection class:

public class ReservationItemProjection
{
    public string ReservationId { get; set; }
    public string CustomerId { get; set; }
    public string EmployeeId { get; set; }
    public DateTime StartTime { get; set; }
    public DateTime EndTime { get; set; }
}

What kind of index and query do I write if I want to find matching
ReservationItemProjections? E.g.:

// invalid example query:
var matches = docs.Query<ReservationItemProjection,
    ReservationItemProjectionsIndex>()
    .Where(x =>
        x.EmployeeId == "employees/1" &&
        x.StartTime >= minTime &&
        x.EndTime <= maxTime)
    .ToList();

Please note, that I do not wish to get a list of Reservation documents but a
list of ReservationItemProjection objects. The documentation says:

But while just getting the documents matching a particular query is useful, we can do better than that. Instead of getting the documents themselves, I want to get the values directly from the index, without getting the full document.

I have already tried using an index like this:

public class ReservationItemProjectionsIndex : 
    AbstractIndexCreationTask<Reservation, ReservationItemProjection>
{
    public ReservationItemProjectionsIndex()
    {
        Map = reservations => 
            from reservation in reservations
            from item in reservation.Items
            select new
            {
                ReservationId = reservation.Id,
                CustomerId = reservation.CustomerId,
                item.EmployeeId,
                item.StartTime,
                item.EndTime
            };
        Store(x => x.ReservationId, FieldStorage.Yes);
        Store(x => x.CustomerId, FieldStorage.Yes);
        Store(x => x.EmployeeId, FieldStorage.Yes);
        Store(x => x.StartTime, FieldStorage.Yes);
        Store(x => x.EndTime, FieldStorage.Yes);
    }
}

Somehow I can’t get the query and index working: it either throws an exception about
not being able to cast from ReservationItemProjection to Reservation or, when I
have been able to get the ReservationItemProjection objects, they will have
included all Items in all Reservations that have even one matching Item, even
though my query has the Where-clause x.EmployeeId == “employees/1”.

Summary: what is the required index? Does the index need only a Map clause or also Reduce or TransformResults? How do I write the query in C#?

  • 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-05-26T11:59:33+00:00Added an answer on May 26, 2026 at 11:59 am

    Kasper,
    In RavenDB, you are querying for documents. While it is technically possible to do what you want, it is usually meaningless to do so, because the projected information doesn’t have the required context to do something with it.

    What is it that you are trying to do?

    For reference, the index would be something like:

     from doc in docs.Items
     from reservation in doc.Reservations
     select new { reservation.EmployeeId, reservation.Start, reservation.End }
    

    Then, mark EmployeeId, Start and End as Store.

    Now, in your query, issue:

      session.Query<...,...>().AsProjection<ReservationProjection>().ToList();
    

    The AsProjection call will let the DB know that you want the values from the index, not the document

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

Sidebar

Related Questions

Suppose I have a document called test1.txt that contains the following numbers: 133213 123123
I have the following XML document: <projects> <project> <name>Shockwave</name> <language>Ruby</language> <owner>Brian May</owner> <state>New</state> <startDate>31/10/2008
I have the following: $(document).ready(function() { var myIframe = document.getElementById('myIframe'); var element = myIframe.contentDocument.createElement('script');
I have the following XML Document (that can be redesigned if necessary) that stores
Never ran into this problem with jQuery before. I have the following: $(document).ready(function() {
I have the following jQuery: $(document).ready(function () { $(.element).draggable(); $(.element).droppable({ drop: function () {
I have the following code: $(document).ready(function() { var id = 'cbx'; var idPrefix =
I have the following code $(document).ready(function() { $('a#slick-toggle').click(function() { $('#slickbox0').toggle(400); return false; }); });
I have the following code: $(document).ready(function(){ $(.yearInner).hide(); $(.year, this).hover( function () { $(.yearInner, this).slideToggle();
I have the following code: $(document).ready(function() { // Manage sidebar category display jQuery(#categories >

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.