We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Apply Sum Extension Method to Word Table Values | LINQ Syntax to Build Report C# .NET

Hello!

I have an Word-Template file in which I loop through the list of “Oberkonto” and each “Oberkonto” object has a list of “Unterkonto”.
This works so far, but when I would like to get the sum of a specific property “SollMonat” of “Unterkonto” then, I get the following error:

An error has been encountered at the end of expression 'u.Sum(p => '. Can not iterate over an instance of type ‘Data_Helper.Models.Unterkonto’

Looping through the list and display the property per “Unterkonto” is not the problem,
but when I would like to get the sum of the property, then I get the error:

Here is the example project, in which I get the error:
Sum_Test.zip (497.2 KB)

Thank you in advance for your answer!

Best regards

Batiatos

@Batiatos,

For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system with ID WORDSNET-22641. We will further look into the details of this problem and will keep you updated here on the status of linked issue. Sorry for the inconvenience.

@awais.hafeez

Ok, thank you for your answer. It’s good to hear, that I don’t make a mistake! :stuck_out_tongue:

I hope you can fix it! :slight_smile:

Best regards

Batiatos

@Batiatos,

WORDSNET-22641 is currently pending for analysis and is in the queue. We will inform you here as soon as we have any updates about it in future.

@Batiatos,

Regarding WORDSNET-22641, the exception is thrown, because the Unterkonto type in your code does not implement IEnumerable, so the Sum extension method cannot be applied to an Unterkonto instance (the same way as it is in pure C#). It seems that you want to get subtotals in a table; if so, then we have attached a modified template achieving this.

@awais.hafeez

Thank you for your help! Now, I get the subtotals as I want! :slight_smile:

Best regards

Batiatos

1 Like