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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:17:34+00:00 2026-06-16T04:17:34+00:00

I hope it’s more clear what I want to do from the code than

  • 0

I hope it’s more clear what I want to do from the code than the title. Basically I am grouping by 2 fields and want to reduce the results into a collection all the ProductKey’s constructed in the Map phase.

public class BlockResult
{
    public Client.Names ClientName;
    public string Block;
    public IEnumerable<ProductKey> ProductKeys;
}

public Block()
{
    Map = products =>
            from product in products
            where product.Details.Block != null
            select new
            {
                product.ClientName,
                product.Details.Block,
                ProductKeys = new List<ProductKey>(new ProductKey[]{
                    new ProductKey{
                        Id = product.Id,
                        Url = product.Url
                    }
                })
            };

    Reduce = results =>
            from result in results
            group result by new {result.ClientName, result.Block} into g
            select new BlockResult
            {
                ClientName = g.Key.ClientName,
                Block =  g.Key.Block,
                ProductKeys = g.SelectMany(x=> x.ProductKeys)
            };
}

I get some weird System.InvalidOperationException and a source code dump where basically it is trying to initialize the list with an int (?).

If I try replacing the ProductKey with just IEnumerable ProductIds (and make appropriate changes in the code). Then the code runs but I don’t get any results in the reduce.

  • 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-16T04:17:35+00:00Added an answer on June 16, 2026 at 4:17 am

    You probably don’t want to do this. Are you really going to need to query in this manner? If you know the context, then you should probably just do this:

    var q = session.Query<Product>()
                   .Where(x => x.ClientName == "Joe" && x.Details.Block == "A");
    

    But, to answer your original question, the following index will work:

    public class Products_GroupedByClientNameAndBlock : AbstractIndexCreationTask<Product, Products_GroupedByClientNameAndBlock.Result>
    {
        public class Result
        {
            public string ClientName { get; set; }
            public string Block { get; set; }
            public IList<ProductKey> ProductKeys { get; set; }
        }
    
        public class ProductKey
        {
            public string Id { get; set; }
            public string Url { get; set; }
        }
    
        public Products_GroupedByClientNameAndBlock()
        {
            Map = products =>
                    from product in products
                    where product.Details.Block != null
                    select new {
                                    product.ClientName,
                                    product.Details.Block,
                                    ProductKeys = new[] { new { product.Id, product.Url } }
                                };
    
            Reduce = results =>
                        from result in results
                        group result by new { result.ClientName, result.Block }
                        into g
                        select new {
                                    g.Key.ClientName,
                                    g.Key.Block,
                                    ProductKeys = g.SelectMany(x => x.ProductKeys)
                                };
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope it's not against rules to post more than 1 question per page. I
Hope here are some with more knowledge about Zend Framework than me, I've been
Hope the title was OK. My problem is that I want to generate an
Hope you all are fine and rocking your code editors. My question is how
hope someone can answer this. Here is some sample code. namespace std { #ifdef
Hope I managed to bait you in using the BSOD title =) I use
Hope the title is not that confusing - honestly said I had no idea
Hope to get a little help from you guys. Im using this script when
Hope fully the title was somewhat descriptive. I have a winform application written in
hope some can help - my webservice returns an object with certain fields i

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.