Hello,
I’m trying your Linq Reporting Engine to generate a report and I need to know what can be done with your library.
I created a DataSet with some DataTables and their DataRelations.
I can navigate between the tables using the relations, but I’m not able to sort the data in a “foreach”.
Case 1 (OK)
This works (no sorting at all):
<<foreach [parent in parentTable]>>
<<foreach [child in parent.childTable]>>
<<[child.Name]>>
<</foreach>>
<</foreach>>
Case 2 (Error)
But this does not work (sort on child data table):
<<foreach [parent in parentTable]>>
<<foreach [child in parent.childTable.OrderBy(c => c.Name)]>>
<<[child.Name]>>
<</foreach>>
<</foreach>>
This is the error generated:
An error has been encountered at the end of expression ‘class in classes.OrderBy(c => c.Name)]>’. Can not resolve method ‘OrderBy’ on type ' '.
Note also that the type name is very strange: a “pipe” followed by 3 spaces (by the way your forum does not show the pipe).
Case 3 (Error)
Also this does not work (sort on parent data table):
<<foreach [parent in parentTable.OrderBy(p => p.Name)]>>
<<foreach [child in parent.childTable]>>
<<[child.Name]>>
<</foreach>>
<</foreach>>
This is the error generated:
An error has been encountered at the end of expression ‘class in classes.OrderBy(c => c.Name)]>’. Can not resolve method ‘OrderBy’ on type ‘System.Data.DataRowCollection’.
Can you help me, please?
@agarberi
To ensure a timely and accurate response, please attach the following resources here for testing:
- Your input Word document.
- Please attach the expected output Word file that shows the desired 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.
Hello,
it required a lot of time to find the problem because using a simple test it worked correctly.
At the end I found where is the problem and it is NOT related to DataSet/DataTable, because also custom C# objects show the same behaviour.
This is the explanation:
If the property which is being used to sort the data is of type “object” instead of real type (“string” or other), then you get the error I reported.
Here the property Name of parentTable (either DataTable column or class property) was of type object
parentTable.OrderBy(p => p.Name)
but changing the property type from object to string solved the problem.
So I think there are 2 errors:
1)
The error message is wrong because it tells you that “OrderBy” method does not exist (if possible, please change the error message).
2)
Your “OrderBy” method seems to not work with values of type “object”, while if you do the same in real C#, it works correctly (if possible, please implement it correctly).
See attached file for C# example of bug 2) to show that it works: LinqOrderByObject.zip (385 Bytes).
Thanks,
Alessandro
@agarberi
Thanks for sharing the detail. It would be great if you please share your template document along with sample application to reproduce your issue at our end. We will investigate the issue on our side and provide you more information.
Aspose.Words - OrderByWithObjectProperty.zip (693.2 KB)
I prepared a full example with 4 different conditions:
- Custom Classes with OrderBy in outer loop
InTableMasterDetail_CustomClasses_OuterOrderBy
- Custom Classes with OrderBy in inner loop
InTableMasterDetail_CustomClasses_InnerOrderBy
- Data Set with OrderBy in outer loop
InTableMasterDetail_DataSet_OuterOrderBy
- Data Set with OrderBy in inner loop
InTableMasterDetail_DataSet_InnerOrderBy
In file Common.cs you can comment and uncomment the first line to have or not have the bug:
#define PROPERTY_AS_OBJECT // This symbol changes the Name property of Client and Manager from String to Object.
With Aspose.Words for .NET 19.8 the error message is always like this:
[…] Can not resolve method ‘OrderBy’ on type […]
Here are the exact error messages you get in the 4 tested conditions:
- InTableMasterDetail_CustomClasses_OuterOrderBy
An error has been encountered at the end of expression ‘in managers.OrderBy(m => m.Name)]>’. Can not resolve method ‘OrderBy’ on type ‘Aspose.Words.Examples.CSharp.LINQ.Common+d__0’.
- InTableMasterDetail_CustomClasses_InnerOrderBy
An error has been encountered at the end of expression ‘in Contracts.OrderBy(co => co.Client.Name)]>’. Can not resolve method ‘OrderBy’ on type ‘System.Collections.Generic.IEnumerable`1[Aspose.Words.Examples.CSharp.LINQ.Contract]’.
- InTableMasterDetail_DataSet_OuterOrderBy
An error has been encountered at the end of expression ‘manager in Managers.OrderBy(m => m.Name)]>’. Can not resolve method ‘OrderBy’ on type ‘System.Data.DataRowCollection’.
- InTableMasterDetail_DataSet_InnerOrderBy
An error has been encountered at the end of expression ‘contract in manager.Contracts.OrderBy(co => co.Clients.Name)]>’. Can not resolve method ‘OrderBy’ on type ' '.
@agarberi
We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-19111. You will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.