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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:05:24+00:00 2026-06-15T05:05:24+00:00

I have a multi map index and need to get the maximum date in

  • 0

I have a multi map index and need to get the maximum date in the Reduce result.

When I try:

Reduce = results => from result in results
                    group result by result.Id into g
                    select new
                    {
                        Id = g.Key,
                        AccountId = g.Select(x => x.AccountId).Where(x => x != null).FirstOrDefault(),
                        Hostnames = g.SelectMany(x => x.Hostnames),
                        NextRenewalDate = g.Select(x => x.NextRenewalDate).Max(),
                        SubscriptionCount = g.Sum(x => x.SubscriptionCount)
                    };

The NextRenewalDate is always null.

However, I can do:

NextRenewalDate = g.Select(x => x.NextRenewalDate).FirstOrDefault,

And I do get a result.

I wonder if this is due to how RavenDB is interpreting the dates within the index. My Reduce Result class is below:

public class ReduceResult
{
    public string Id { get; set; }
    public string AccountId { get; set; }
    public string[] Hostnames { get; set; }
    public DateTime NextRenewalDate { get; set; }
    public int SubscriptionCount { get; set; }
}

Update

I’ve since been able to get the index working but only if I cast the DateTime to an ISO8601 string. My full index is below:

public class Account_Sites : AbstractMultiMapIndexCreationTask<Account_Sites.ReduceResult>
{
    public Account_Sites()
    {
        AddMap<CMS.Domain.Site>(sites => from site in sites
                                         from url in site.Urls
                                         select new
                                         {
                                             Id = site.Id,
                                             AccountId = (string)null,
                                             Hostnames = new[] { url.Hostname },
                                             SubscriptionDueDate = DateTime.MinValue,
                                             SubscriptionStartDate = DateTime.MinValue
                                         });

        AddMap<Domain.Account>(accounts => from account in accounts
                                           from siteId in account.Sites
                                           from subscription in account.Subscriptions
                                           where subscription != null
                                           select new
                                           {
                                               Id = siteId,
                                               AccountId = account.Id,
                                               Hostnames = new string[0],
                                               SubscriptionDueDate = subscription.NextRenewalDate,
                                               SubscriptionStartDate = subscription.StartDate
                                           });

        Reduce = results => from result in results
                            group result by result.Id into g
                            select new
                            {
                                Id = g.Key,
                                AccountId = g.Select(x => x.AccountId).Where(x => x != null).FirstOrDefault(),
                                Hostnames = g.SelectMany(x => x.Hostnames),
                                SubscriptionDueDate = g.Max(x => x.SubscriptionDueDate.ToString("o")), // ISO 8601 format e.g. 2012-10-22T12:51:03.0263843+00:00
                                SubscriptionStartDate = g.Max(x => x.SubscriptionStartDate.ToString("o"))
                            };
    }

    public class ReduceResult
    {
        public string Id { get; set; }
        public string AccountId { get; set; }
        public string[] Hostnames { get; set; }
        public DateTime SubscriptionDueDate { get; set; }
        public DateTime SubscriptionStartDate { get; set; }
    }
}

Update 2

I’ve posted a complete failing test below. Daniel’s test does work but the following fails. Changing the TestSubscription.EndDate to DateTime.Now (instead of UtcNow) however does work. This is using build 1.2.2103-Unstable.

public class TestAccount
{
    public string Id { get; set; }
    public List<string> Sites { get; set; }
    public List<TestSubscription> Subscriptions { get; set; }

    public TestAccount()
    {
        Sites = new List<string>();
        Subscriptions = new List<TestSubscription>();
    }
}

public class TestSubscription
{
    public DateTime EndDate { get; set; }
}

public class TestSite
{
    public string Id { get; set; }
    public string Hostname { get; set; }
}

public class SitesWithSubscriptions : AbstractMultiMapIndexCreationTask<SitesWithSubscriptions.Result>
{
    public SitesWithSubscriptions()
    {
        AddMap<TestSite>(sites => from site in sites
                                  select new
                                  {
                                      SiteId = site.Id,
                                      Hostname = site.Hostname,
                                      SubscriptionEndDate = DateTime.MinValue
                                  });

        AddMap<TestAccount>(accounts => from account in accounts
                                        from siteId in account.Sites
                                        from subscription in account.Subscriptions
                                        select new
                                        {
                                            SiteId = siteId,
                                            Hostname = (string)null,
                                            SubscriptionEndDate = subscription.EndDate
                                        });

        Reduce = results => from result in results
                            group result by result.SiteId into g
                            select new
                            {
                                SiteId = g.Key,
                                Hostname = g.Select(x => x.Hostname).Where(x => x != null).FirstOrDefault(),
                                SubscriptionEndDate = g.Max(x => x.SubscriptionEndDate)
                            };
    }

    public class Result
    {
        public string SiteId { get; set; }
        public string Hostname { get; set; }
        public DateTime SubscriptionEndDate { get; set; }
    }
}

    public class SitesSpecs : RavenSpecs
{
    static IEnumerable<SitesWithSubscriptions.Result> results;

    Establish ctx = () =>
    {
        using (var session = Store.OpenSession())
        {
            var site = new TestSite { Hostname = "www.dev.com" };
            session.Store(site);

            var account = new TestAccount();
            account.Subscriptions.Add(new TestSubscription { EndDate = DateTime.UtcNow });
            account.Sites.Add(site.Id);
            session.Store(account);

            session.SaveChanges();
        }           
    };

    Because of = () =>
    {
        using (var session = Store.OpenSession())
        {
            results = session.Query<SitesWithSubscriptions.Result, SitesWithSubscriptions>()
                .Customize(x => x.WaitForNonStaleResults())
                .ToList();
        }
    };

    It Should_return_sites_with_subscription_end_dates = ()
        =>
    {
        results.Count().ShouldEqual(1);
        results.First().SubscriptionEndDate.Date.ShouldEqual(DateTime.UtcNow.Date);
    };
}
  • 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-15T05:05:25+00:00Added an answer on June 15, 2026 at 5:05 am

    This turned out to be a bug in RavenDB and was fixed in build 2145. Full details at http://issues.hibernatingrhinos.com/issue/RavenDB-718

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

Sidebar

Related Questions

We have developed map base application. We have implemented multi-threading for display data on
I have a multi-line text view that can get quite large. When the user
I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add
I need to have a Map within a Map in one of my Triggers.
From a group of span elements, I want to get the values of the
In my multi-threaded project(C# 3.5), I have many codes simliar to this: Map map;
I have a multi-threaded application that creates 48 threads that all need to access
I need a multi-threaded Map object to use in my web server's caching, and
I have 4 textures used in a multi-pass effect with the color map at
I have a multi-dimensional array like so: var map = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]; I then have

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.