BusinessObject source doesn't populate members of C# anonymous type

Stimulsoft Reports.WEB discussion
Post Reply
jkoo
Posts: 64
Joined: Fri Aug 19, 2011 8:08 pm

BusinessObject source doesn't populate members of C# anonymous type

Post by jkoo »

For example, in the below code, Name and Company of 'Department' are not displayed in dictionary.
But when anonymous type is used at collection, it works fines(Looks at the Phones).
It happens at both winform and web.
Please refer to the below image.

Thanks

Code: Select all

var data = from EmployeeITypedList emp in CreateBusinessObjectsITypedList.GetEmployees()
                   select (
                   new
                   {
                       Name = emp.EmployeeName,
                       Department = new { Name = emp.Department.DepartmentName, Company = emp.Department.Company.CompanyName},
                       Phones = from Phone phone in emp.Phones
                                select (new { Area = "xxx", Number = phone.Number })
                   }
                   );

        report.RegBusinessObject("employee", data);
Attachments
1297.BusinessObjectsWeb4.zip
(63.87 KiB) Downloaded 275 times
1296.AnonymousType.png
1296.AnonymousType.png (8.71 KiB) Viewed 2020 times
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

BusinessObject source doesn't populate members of C# anonymous type

Post by HighAley »

Hello.
jkoo wrote:For example, in the below code, Name and Company of 'Department' are not displayed in dictionary.
But when anonymous type is used at collection, it works fines(Looks at the Phones).
It happens at both winform and web.
Please refer to the below image.
For working with Business Objects we present Business Object structure as structure of subclasses. Then this structure is used while compiling report and to receive data while rendering report.

But if you use anonymous types in runtime impossible to determine type of object due to a strange error in .NET Framework that occurs when you try to get the type of an anonymous object. Accordingly, we can not properly create the class structure, compile a report and then get the data.

Therefore, we do not support with anonymous types.

Thank you.
jkoo
Posts: 64
Joined: Fri Aug 19, 2011 8:08 pm

BusinessObject source doesn't populate members of C# anonymous type

Post by jkoo »

Thanks for the explanation.
But I'm wondering why IEnumerable list that have anonymouse type as an element type works fine.
That is,

Code: Select all

from EmployeeITypedList emp in CreateBusinessObjectsITypedList.GetEmployees()
                   select (
                   new
                   {
                         Name = ...;
                    }
                   )

or
Phones = from Phone phone in emp.Phones
                                select (new { Area = "xxx", Number = phone.Number })
I think anoymouse type is working at Emplyoee list and phone list.

And, as I know, anoymouse type is a compile time feature and a not run time.
So I think an anonymous type is no different from any other reference type except fore typename is created automaically.
Sorry for bothering you. I just want to make sure it.

Thanks
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

BusinessObject source doesn't populate members of C# anonymous type

Post by Alex K. »

Hello,

The problem in the Framework is not clear. If you use an items array of the anonymous type, then there is no problem, in other cases, errors occurs. The error occurs in a method that should return the object type.

Thank you.
Post Reply