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

  • Home
  • SEARCH
  • 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 8565275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:23:20+00:00 2026-06-11T17:23:20+00:00

My Sum and Max calls on last used and usage count are wrong. They

  • 0

My Sum and Max calls on last used and usage count are wrong. They are always the value that is stored in the second maps value which is currently set to 0. I can make it -100 and that is what the reduce result will be. I noticed someone saying that you should make it an array but I don’t understand how that helps. I have a linq expression over objects using the map/reduce that works properly assuming that the two maps are unioned together.

Here’s the data => https://gist.github.com/940ccca1b0f8917e9eaf

I want to support a query like

        var stats = Session.Query<MultiMapApiKeyStats.ApiKeyStats, MultiMapApiKeyStats>()
            .Customize(x => x.WaitForNonStaleResultsAsOfNow())
            .Where(x => x.AccountId == Account.Id)
            .OrderBy(x => x.Key).ToList();

and build a table like
table

 public MultiMapApiKeyStats()
        {
            AddMap<KeyUsageBase>(uses => from use in uses
                                         select new
                                         {
                                             AccountId = use.AccountId,
                                             ApiKeyId = use.ApiKeyId,
                                             Key = (string)null,
                                             UsageCount = 1,
                                             LastUsed = use.LastUsedTicks,
                                             Pattern = (string)null,
                                             Status = ApiKey.KeyStatus.None,
                                             Type = ApiKey.ApplicationType.None
                                         });
            AddMap<ApiKey>(keys => from key in keys
                                   select new
                                          {
                                              AccountId = key.AccountId,
                                              ApiKeyId = key.Id,
                                              Key = key.Key,
                                              UsageCount = 0,
                                              LastUsed = 0,
                                              Pattern = key.Pattern,
                                              Status = key.ApiKeyStatus,
                                              Type = key.Type
                                          });


            Reduce = results => from result in results
                                group result by result.ApiKeyId
                                    into g
                                    select new
                                           {
                                           AccountId = g.Select(x => x.AccountId).FirstOrDefault(),
                                           ApiKeyId = g.Key,
                                           Key = g.Select(x => x.Key).FirstOrDefault(x => x != null),
                                           UsageCount = g.Sum(x => x.UsageCount),
                                           LastUsed = g.Max(x => x.LastUsed),
                                           Pattern = g.Select(x => x.Pattern).FirstOrDefault(),
                                           Status = g.Select(x => x.Status).FirstOrDefault(),
                                           Type = g.Select(x => x.Type).FirstOrDefault()
                                           };
  • 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-11T17:23:22+00:00Added an answer on June 11, 2026 at 5:23 pm

    The indexing error sequence contains no matching elements is a result of invoking First on an empty collection which is why you should use FirstOrDefault. Also, referencing your own classes in map and reduce declarations will cause errors because RavenDB can’t resolve those types at indexing time.

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

Sidebar

Related Questions

i have this rad combo box (aka dropdownlist) with items count sum max min
I would like to do the following: SELECT sum(max(field-10,000,0)) from TABLE as in, I
I am trying to get the sum(comprate) for only max(effdt) having max(id) from the
Simple sum of digits code. It compiles but when executed, the last cout gives
We are looking to sum the output of an expression meaning that it does
I want to select some entries based on a max+sum condition. mytable ---------- id
I have a linq statement which calls a stored proc and returns a list
How to find Min,Max,Sum of given array? int[] number = { 1, 2, 3,
I have this table similar to MySQL - get sum() grouped max() of group
I'm trying to get the highest value of the sum of the childs of

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.