This is a migrated thread and some comments may be shown as answers.

Binding to dynamic type with ObjectDataSource

7 Answers 291 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 04 Jul 2016, 09:38 PM

Hello,

I have an object data source pointing at a of List<DynamicJsonObject>. The problem is that the report throws an error when I reference a field name because it doesn't think the field exists. So, if I create a textbox and do "=Fields.LocationName", it gets an error when I preview it. However, this code works:

private void detail_ItemDataBound(object sender, EventArgs e)
        {
            var detail = (Telerik.Reporting.Processing.DetailSection)sender;
            Telerik.Reporting.Processing.TextBox txt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.GetChildByName(detail, "txtLocationName");
            var data = (dynamic)detail.DataObject.RawData;
            txt.Value = data.LocationName;
        }

 

This is presumably working because I can cast the raw data as dynamic. 

I'm not wedded to this way of doing this, but I do need a way to report on json data. Is this possible?

Thanks.

 

7 Answers, 1 is accepted

Sort by
0
Accepted
Katia
Telerik team
answered on 05 Jul 2016, 01:44 PM
Hello Mike,

Dynamic objects are not supported by ObjectDataSourceComponent out-of-the-box as the reporting engine expects the collection to contain a list of business objects with known properties.

You can check the approach suggested in How to: Use ObjectDataSource with ExpandoObject KB article where a custom descriptor is provided in order to determine the actual properties of the object.

You can test modifying the suggested approach to work in your particular scenario and with the type of objects you use.



Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Baran
Top achievements
Rank 1
answered on 09 Nov 2016, 02:10 PM
Are there any updates on the new version about this?
0
Baran
Top achievements
Rank 1
answered on 09 Nov 2016, 02:12 PM

I am trying to conver JObject to an anonymous type. Maybe somebody can help me.

http://stackoverflow.com/questions/40507909/convert-jobject-to-anonymous-object

0
Baran
Top achievements
Rank 1
answered on 09 Nov 2016, 02:12 PM

I am trying to find different solutions.

http://stackoverflow.com/questions/40507909/convert-jobject-to-anonymous-object

0
Katia
Telerik team
answered on 09 Nov 2016, 04:05 PM
Hi Baran,

It is not in our short-term plans to add support for dynamic types by ObjectDataSource component.

You can still test if the approach provided in How to: Use ObjectDataSource with ExpandoObject KB article can be useful in your scenario.


Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Baran
Top achievements
Rank 1
answered on 10 Nov 2016, 04:29 PM

I found a solution, maybe telerik can help us by supporting json data as datasource object.

http://stackoverflow.com/a/40532370/202036

0
Katia
Telerik team
answered on 10 Nov 2016, 04:51 PM
Hello Baran,

For JSON data, the recommended approach is first to deserialize it and then use in ObjectDataSource.


Regards,
Katia
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Mike
Top achievements
Rank 1
Answers by
Katia
Telerik team
Baran
Top achievements
Rank 1
Share this question
or