none
Accessing child properties in an object data source RRS feed

  • Question

  • We are trying to create reports for the MS Report Viewer using and Object data source. We can get some basic functionality working, but are having a problem drilling down on our objects and accessing child properties that are multiple levels deep. Take the following object structure:

    ObjectA
    - NameForA : string
    - ID : int
    - ObjectB
        - NameForB : string
        - ObjectC
            - NameForC : string

    The Data Source window shows the entire object hierarchy correctly, but only properties of ObjectA that are of simple data type (numeric/string types, etc) can be dragged on to the report and work correctly. It allows you to drag the NameForB property on to the report, but the Value expression it generates (Fields!NameForB.Value) does not work. After some searching, we found that we could manually modify the .rdlc file to access and successfully display the NameForB property with an expression of "Fields!ObjectB.Value.NameForB".

    At this point we have our actual question: how do we access properties that are more than 2 levels deep on our object hierarchy (for example, the NameForC property above)? We have tried various expressions like "Fields!ObjectB.Value.ObjectC.NameForC", "Fields!ObjectB.Value.ObjectC.Value.NameForC", etc., but have not been able to access those properties.

    Any help would be greatly appreciated.
    Wednesday, June 4, 2008 2:45 PM

All replies

  • After some more searching, we have found a solution in the comments of this blog post: http://blogs.msdn.com/tudortr/archive/2006/04/10/NestedObjectsDataSource.aspx (the original blog post also contains the syntax for accessing 3rd+ level properties).

    The objects we are using for the report data sources are in a different assembly from the Report Viewer control, so we need to call ExecuteReportInCurrentAppDomain on the viewer's LocalReport in order to access the 3rd+ level properties. Why that is not needed for the first and second level properties, I don't know, but it did the trick for us. I just wanted to post this here in case anyone else has this problem (and as much trouble finding a solution as we had).
    Friday, June 6, 2008 6:50 PM
  • Do you have any experience in accessing lists in these objects? lets say if your ObjectB in addition to NameForB, instead of an ObjectC contains a list of ObjectC. how can you work with that? in my head it should be as easy as having a list for objectA and then something for ObjectB and a list for ObjectC in ObjectB... but I can't really get it to work...
    Friday, December 12, 2008 9:25 AM
  • No, we have tried doing this a few ways but have not figured out how. It seems like you should just be able to nest tables or something similar, but that doesn't seem to work.

    What we have done to work around it in a few instances is to make a new class that flattens the data out, and then grouping that data within the report. That's not ideal though, and doesn't really work for some situations.
    Tuesday, February 24, 2009 10:36 PM
  •  

    andyjeigh, svishy

     

    Have you tried grouping using nested objects? I posted a issue around that a while ago and have not found a substantial answer for it. Here’s the link

     

    http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/da130955-99c3-434c-9d27-f33903fc8306

     

    I have also reported this issue to Microsoft Connect with a sample application depicting the error.

     

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=411823

     

    I have tried setting the ExecuteReportInCurrentAppDomain but for no use. Eventually I flattened the class with nested object, to make things work.


    -= JL =-
    Wednesday, February 25, 2009 5:56 AM