In reporting engine, keep base element attribute when using SelectMany

I am building a template to create a report from an internal data source generated by our application. The data source is a list of plants containing a list of processes, with a value for each process, and I would like to generate a table with the following columns, ordered by value:

Plant name | Process name | Value

However, as it is a list of lists, I cannot simply use OrderBy. I first need to flatten the list (sadly I have no control over the data source).

It is feasible with SelectMany, but then I just have a flat list of processes, I no longer have the plant names, so I managed to list and order my values but without the necessary context.

I know that in “real .Net”, it is possible to define a function describing the object we want to generate, as shown in Enumerable.SelectMany Method (System.Linq) | Microsoft Learn, something like:
.SelectMany(petOwner => petOwner.Pets, (petOwner, petName) => new { petOwner, petName })

However, when I tried this syntax in a report template, it failed with Error! Can not resolve method 'SelectMany' on type 'tl'.. Does it mean it is not supported or did I mess it up somewhere?

Here is a minimal program with a simple JSON data source I used to test:
testSelectManyReportingEngine.zip (106.7 KB)

Thanks in advanced!

@Leyan

LINQ Reporting Engine supports only a subset of C# features, it does not support the mentioned SelectMany overload. To have a plant-line connection, another approach should be used: Changing the last part of the shared template like that:

<<var [plantlines3 = plants.SelectMany(plant=> plant.lines.Select(line => new { plant, line })) ]>>
<<foreach [x in plantlines3]>>
Line: <<[x.plant.name]>><<[x.line.name]>><<[x.line.value]>><</foreach>>

However, when doing this, an exception is thrown upon running the expression. This seems to be a bug as the syntax is valid. We are going to log the issue into our tracking system.

@Leyan
For the sake of further analysis and possible correction, we have opened the following new ticket(s) in our internal issue tracking system and will work on them according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-29164

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-29164) have been fixed in this Aspose.Words for .NET 26.4 update also available on NuGet.

@ivan.lyagin Thanks a lot for the solution and quick correction, I confirm it works.

1 Like