LINQ Reporting - Group By Iterations

I am using the latest version of Aspose.Words, populating a report with the LINQ Rpeorting Engine.

I have seen examples using GroupBy, but these examples never iterate over the returned collection, it usually just shows the Key.

Imagine this Layout:

<<foreach [in mainlist]>> <<[listName]>>

<<foreach [in sublist.GroupBy(c=>c.groupValue)]>> - <<[Key]>>

<<foreach [in Values]>> --<<[name]>>, <<[color]>><</foreach>>



Expected Output Would be:

–Aplples, red
–Oranges, orange
–Lettuce, green
–Broccoli, green

This layout works for me - except this part <<foreach [in Values]>>. How can I loop through the IEnumarble that the GroupBy returns? What is the name of the list the groupBy returns?


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Here is a sample of what I’m trying to do: (416.1 KB)

        const string resourceBase = "LINQReportingGroupBy";
        string asposeTemplate = "templateWithGrouping.docx";
        List<Food> foods = new List<Food>();
        foods.Add(new Food { name = "Lettuce", category = "vegetable", color = "green" });
        foods.Add(new Food { name = "Broccoli", category = "vegetable", color = "green" });
        foods.Add(new Food { name = "Apple", category = "fruit", color = "red" });
        foods.Add(new Food { name = "Orange", category = "fruit", color = "orange" });

        Assembly thisAssembly = Assembly.GetExecutingAssembly();
        Stream someStream = thisAssembly.GetManifestResourceStream(String.Format("{0}.{1}", resourceBase, asposeTemplate));
        Document doc = new Document(someStream);
        ReportingEngine engine = new ReportingEngine();

        // Execute the build report.
        engine.BuildReport(doc, foods, "foods");

My template is as below:

<<foreach [in foods.GroupBy(c=>c.category)]>>
       <<foreach [in Value]>>
                 <<[name]>>	<<[color]>>

The error I receive is System.InvalidOperationException: 'An error has been encountered at the end of expression ‘in Value]>’. Can not get the value of member ‘Value’ on type

I’ve not seen this covered in the documentation anywhere, so I’m guessing at “Value” as the name of the list returned from the GroupBy statement.


Thanks for sharing the detail. We are working over your query and will get back to you soon.


Thanks for your patience. In your case, we suggest you please read following article.
In-Table Template with Filtering, Grouping, and Ordering

Moreover, please check the LINQ code example from Github repository.

I have read over both of these examples multiple times. I do not see anywhere that is iterating over the enumerable of the group by. If I have missed this, please point me in the direction of a specific example in the github repository. I submitted a sample project - I don’t understand why I did that only to be redirected to existing documentation.


Thanks for your inquiry. For your case, we have logged a feature request as WORDSNET-17382 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.


Thanks for your patience. This feature is already supported by Aspose.Words but using another syntax like in the following example:

<<foreach [in mainlist]>> <<[listName]>>
<<foreach [group in sublist.GroupBy(c=>c.groupValue)]>> - <<[Key]>>
<<foreach [in group]>> --<<[name]>>, <<[color]>><</foreach>>

That is, a group represents an enumeration of grouped items. In fact, this is exactly the same behavior as .NET built-in IEnumerable.GroupBy extension method provides. This is also briefly explained in extension methods.

A post was split to a new topic: LINQ Reporting GroupBy Issue