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

Getting information from a IEnumerable inside a model

1 Answer 211 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dalton
Top achievements
Rank 1
Dalton asked on 28 Dec 2015, 07:28 PM

I'm trying to set up a report to list different numbers off, ill use a fake model to show.

public class FakeModel

{

      public string Name {get; set;}

      public int Age {get; set;}

      public IEnumerable<ParentModel> Parents {get; set;}

}

 

public class ParentModel

{

      public int Age {get; set;}

      public string JobName {get; set;}

      public DateTime DateOfBirth {get; set;}

}

 

My problem is I'm using FakeModel as my DataSource and it works fine for the first part of my report for the information I need. Then later in the report I need to use the list of ParentModels to display all the information listed and when I try to use the normal way for selecting values with the ... button, it shows a option to expand the list but I click and nothing changes except the button going away. The goal is to display the list of ParentModels on my report.

 

I'm using the Telerik Report Q3 2015 Wizard.

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 29 Dec 2015, 12:03 PM
Hi Dalton,

In general for binding to IEnumerable<T> you need to use ObjectDataSource ComponentIn case, the DataSource is a business object the DataMember property specifies the name of the method which should be invoked to retrieve the data. To populate your query object use the arguments of this method which can be specified through the Parameters collection of the ObjectDataSource component.

Please find more detailed information in How to bind to a BusinessObject and Using with the ObjectDataSource Component.

When there is another business object property (Parents) within your business object (FakeModel) we do not drill down into the hierarchy. To use the inner object (Parents) you have to bind a separate Data Item to it using expressions and Bindings. For more detailed information, please follow the Use DataObject as data source for nested data items (Table, List, Crosstab, Graph) section of the How to use ReportItem.DataObject property in expressions help article. This way you can bind the DataSource  property of a data item to a given object/collection property from your business object and the data item will display the inner items. The binding expression which you will have to use in your particular scenario will be: = ReportItem.DataObject.Parents.
Note that the inner items will not be visible in the expression editor at design-time, so you will need to type the data field names manually in expressions, for example: = Fields.JobName.

Regards,
Katia
Telerik
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
Dalton
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or