Good afternoon everybody,
we’re starting using Aspose.Words library, but receive the attached exception during build-report call.
Can you help me finding where the error is in template ? I didn’t find any reference to a template row number or portion of code to understand better where the error is.
The exception message is “A single child data row is expected, but multiple child data rows are found.”
@Jackomino Could you please attach your template along with sample code and data that will allow us to reproduce the problem? We will check the issue and provide you more information.
Good morning, I made a simple test: just removed a “Where” condition and template builds properly
Not working code
<<foreach
[F in PCL.M20_PCL_HDR?.M22_FLD_STM.Where(fst => fst?.M22_FLD_STM_UDA_VAL?.FLD_STM_UDA_VALUE==“C” || fst?.M22_FLD_STM_UDA_VAL?.FLD_STM_UDA_VALUE==“GTC”).
OrderBy(fs => fs.M22_FLD?.FLD_CODE)?.GroupBy(fs => new { Fluid = fs.M22_FLD?.FLD_CODE })]>><<[F.IndexOf() != 0 ? " , " : “”]>><<[Key?.Fluid]>><>
Working code
<<foreach
[F in PCL.M20_PCL_HDR?.M22_FLD_STM.
OrderBy(fs => fs.M22_FLD?.FLD_CODE)?.GroupBy(fs => new { Fluid = fs.M22_FLD?.FLD_CODE })]>><<[F.IndexOf() != 0 ? " , " : “”]>><<[Key?.Fluid]>><>
I keep investigating, but it would be great (if possible in building process) to have in the
A single child data row is expected, but multiple child data rows are found.
exception a reference to paragraph is being built, to find out easily where the problem is
I attached image with DataSet used by report, it’s strange that without “Where” operation all works properly, whilst defining a condition that will reduce data we got the error.
Starting from Aspose.Words 21.8, LINQ Reporting Engine includes text of an expression caused an exception during evaluation, so you can find the expression by its text in a template.
Together with the exception message, this tells that a portion of your template expression containing the Where condition tries to access a single related data row but gets multiple related data rows. For example, fst?.M22_FLD_STM_UDA_VAL?.FLD_STM_UDA_VALUE tries to access a single related row by ?.M22_FLD_STM_UDA_VAL. It may be that this returns multiple related rows for some value of fst, so you get the error. Without having a sample template, data, and code reproducing the issue, it is hard to tell more precisely.
Unfortunately exception in this case didn’t tell me any template expression related to error, but finally I found where the problem is.
We’re trying to prepare a test case, to let you investigate, but it’s quite hard considering our app.
You perfectly found the problem: we’re trying to collect a subset of row using “Where” as in M22_FLD_STM_UDA_VAL table we can have many rows related to the same “fst”, for example in given DataSet image there are 2 rows for the same fst (PROJECT_ID, FLD_STM_ID and REV_ID)
Please make sure you use Aspose.Words 21.8 or later.
Then, I would suggest treating fst?.M22_FLD_STM_UDA_VAL as a collection of related rows in a template expression. That is, your Where condition could be rewritten in the following way then:
We updated Aspose.Words version and the exception it’s precise now
An error has been encountered while evaluating the expression or statement ‘FS in M22_FLD_STM.Where(fs => fs?.M22_FLD_STM_UDA_VAL?.FLD_STM_UDA_VALUE==“C” || fs?.M22_FLD_STM_UDA_VAL?.FLD_STM_UDA_VALUE==“SYN”).OrderBy(fs => fs.CUS0593_TBL001?.FLD_STM_SORT).ThenBy(fs => fs.M22_FLD_STM_HDR.FLD_STM_CODE)]>’. A single child data row is expected, but multiple child data rows are found.
Then I tried your suggestion, but I get this error:
An error has been encountered at the end of expression ‘F in PCL.M20_PCL_HDR?.M22_FLD_STM.Where(fst => fst?.M22_FLD_STM_UDA_VAL?.Any(v => v?.FLD_STM_UDA_VALUE==“C” || v?.FLD_STM_UDA_VALUE==“GTC”)).’. Can not resolve method ‘Where’ on type ' '.
Thanks a lot again for your support and patience
Giacomo
Seems like Where expects a lambda function returning a Boolean value, but null-conditional member access transforms Any's result to Nullable<Boolean>, that is why Where cannot be found for the given argument. To resolve this, you can use one of the following options:
If possible, use common member access rather than null-conditional one like this: Where(fst => fst.M22_FLD_STM_UDA_VAL.Any(v => v.FLD_STM_UDA_VALUE==“C” || v.FLD_STM_UDA_VALUE==“GTC”)).
Otherwise, compare Any's result with true like this: Where(fst => fst?.M22_FLD_STM_UDA_VAL?.Any(v => v?.FLD_STM_UDA_VALUE==“C” || v?.FLD_STM_UDA_VALUE==“GTC”) == true).
Thanks a lot for your help, not only for giving the right code, but also to explain me the reason why we get the error on “type”: I’m a beginner with Aspose.Words library and these information are really useful to understand how to write template code with Linq reporting engine