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

OpenAccess DataSource Child Objects

1 Answer 105 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
alo
Top achievements
Rank 1
alo asked on 12 Sep 2011, 06:52 AM
Hello,

I'm just starting to work with Telerik Reporting along with OpenAccess and I'm running into some difficultly that I thought would be relatively straight forward using the two products together.  I'm sure I'm just missing something simple, but I just can't seem to figure it out.

I'm using an OpenAccess DataSource to build a report.  I can pull my object properties and the navigation properties representing my foreign key relationships from the Data Explorer to my report just fine.  However, I can't seem to figure out how to get data from the 1:1 or 1:M navigation properties that are represented as collections.  I've tried using the List control and creating a binding to the child object, but the following error shows up on my report when previewing:

"An error has occurred while processing Table 'list1':
The expression contains object 'MyChildObjects' that is not defined in the current context."

I've noticed in the Data Explorer that when I expand the child object none of the properties show up like when I expand an object representing a foreign key relationship.

I'm trying to pull one instance of the child object collection and include it in the report.  This could either be the first instance or based on some other logic (like a where clause).

Thanks for your assistance,

Al

1 Answer, 1 is accepted

Sort by
0
Ivan
Telerik team
answered on 15 Sep 2011, 12:02 PM
Hello Alo,

There is a very good reason why you cannot drill through navigation properties of one-to-many relationships in Data Explorer: that is because you cannot bind to both the master and the detail entity at the same level of the report, or at least that would not give you the expected result. For example, lets assume we have two entities: ProductModel and Product in a one-to-many relationship. If you bind, say two TextBox components in the DetailSection to both the ProductModel and Product entities, which Product entity should be displayed for each ProductModel entity? The default behavior is to pick whichever comes first, however that is not something you would normally want.

The proper way to create a master-detail report is to bind the report to the master entities and then use some kind of a data repeater component (e.g. Table, List, SubReport) to list all the detail entities for a given master entity. Considering the above example, lets assume the ProductModel entity exposes a Products property that allows you to enumerate through all the products for the current model. Then you can use a binding expression like the following one to bind the DataSource property of the data repeater component to the Products property of the current ProductModel entity:

=ReportItem.Parent.DataObject.Products

Please, check the sample solution attached to this post: the ReportSimpleBinding report demonstrates the above approach. You would need the AdventureWorks sample database installed in order to run it.

Another and more flexible approach is to extend your entity model using a partial class with additional methods for data retrieval. This way you can execute an arbitrary LINQ query against your entities, pass parameters to filter data etc. The ReportExtendedModel report from the attached sample solution demonstrates this. It uses two data source components - one for the master entities and one for the detail ones. The data sources are linked together in a master-detail relationship using data source parameters.

Hope this helps.

Best wishes,
Ivan
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
General Discussions
Asked by
alo
Top achievements
Rank 1
Answers by
Ivan
Telerik team
Share this question
or