none
How do I Navigate / Walk through Entity hierarchy in ReportViewer RDLC? RRS feed

  • Question

  • Hi

    I've used the examples in earlier Posts w.r.t. Entities and ReportViewer Control to create an ObjectDataSource for my LINQ Entities and directly bound it a RDLC in local mode, and successfully set the Data Source at run time.

    However, at this stage it seems that the RDLC created only allows access to the direct / immediate properties of the entity that I've bound.
    e.g. in the below example I need to navigate the entity graph :
    Service->ServiceType->Name

    Has anyone managed to successfully 'walk' through the entity graph in RDLC, or will I need to flatten my entity graph in order to use properties of related entities in my report (i.e. First need to denormalise the complex Entity into a new wide Entity class containing all properties)

    (i.e. meaning that there isn't any point in using entities in an RDLC. The LINQ language extensions could be used to create the 'flattened' entity, e.g. using a new anonymous class)

    What I need is something like the 3rd Field listed below, where I need to reference a property of a subentity in the report

        <DataSet Name="Service">
          <Fields>
            <Field Name="Code"> <!-- Simple Field is a direct Property on the Entity identified for the ObjectDataSource-->
              <DataField>Code</DataField>
              <rd:TypeName>System.String</rd:TypeName>
            </Field>
            <Field Name="ServiceType"> <!-- Many : One Entity Property on the Entity identified for the ObjectDataSource-->
              <DataField>ServiceType</DataField>
              <rd:TypeName>MyAssembly.Entities.ServiceType</rd:TypeName>
            </Field>
            <Field Name="ServiceTypeName"> <!-- "walked" field on the above Sub Entity-->
              <DataField>ServiceType.Name</DataField>* Doesn't work
              <rd:TypeName>System.String</rd:TypeName>
            </Field>

    Thanks in advance

    Stuart
    Sunday, August 30, 2009 10:00 AM

All replies

  • Hi

    I've used the examples in earlier Posts w.r.t. Entities and ReportViewer Control to create an ObjectDataSource for my LINQ Entities and directly bound it a RDLC in local mode, and successfully set the Data Source at run time.

    However, at this stage it seems that the RDLC created only allows access to the direct / immediate properties of the entity that I've bound.
    e.g. in the below example I need to navigate the entity graph :
    Service->ServiceType->Name

    Has anyone managed to successfully 'walk' through the entity graph in RDLC, or will I need to flatten my entity graph in order to use properties of related entities in my report (i.e. First need to denormalise the complex Entity into a new wide Entity class containing all properties)

    (i.e. meaning that there isn't any point in using entities in an RDLC. The LINQ language extensions could be used to create the 'flattened' entity, e.g. using a new anonymous class)

    What I need is something like the 3rd Field listed below, where I need to reference a property of a subentity in the report

        <DataSet Name="Service">
          <Fields>
            <Field Name="Code"> <!-- Simple Field is a direct Property on the Entity identified for the ObjectDataSource-->
              <DataField>Code</DataField>
              <rd:TypeName>System.String</rd:TypeName>
            </Field>
            <Field Name="ServiceType"> <!-- Many : One Entity Property on the Entity identified for the ObjectDataSource-->
              <DataField>ServiceType</DataField>
              <rd:TypeName>MyAssembly.Entities.ServiceType</rd:TypeName>
            </Field>
            <Field Name="ServiceTypeName"> <!-- "walked" field on the above Sub Entity-->
              <DataField>ServiceType.Name</DataField>* Doesn't work
              <rd:TypeName>System.String</rd:TypeName>
            </Field>

    Thanks in advance

    Stuart
    Hello,
      I'm having exactly the same problem. We've been using Crystal Reports for more than 10 years and are considering moving to Report Services due to the integration capabilities with our Business Entities. But this "possible" limitation makes things a little harder and personally I think it's a major flaw if it's true. I'm looking forward to the answer to this post.
    Wednesday, October 7, 2009 10:22 AM
  • Has Stuart's question been answered?  Besides the issue of traversing the hierarchy of object relationships in rdlc, I have the additional dilemma of having named both parent and child primary keys as 'ID', thinking there would be no ambiguity between references to 'Parent.ID' and 'Parent.Child.ID'.  Unfortunately, whenever a related entity is referenced as a data source in the rdlcdesigner, I end up with the Parent's ID being returned.

    So how are child entities referenced in the report deisgner?  Do I need to have unique names for Primary and Foreign key references?

    Thanks,

         -BGood
    Sunday, November 29, 2009 6:16 PM
  • Some further research reveals divergent opinions.  At http://www.gotreportviewer.com/objectdatasources/index.html, documentation suggests that object hierarchies can be traversed using syntax like =Fields!HomeAddress.Value.Zip.  When I tried this on my system (VS2008 Standard), this systax works, but the drag-drop implementation of the report designer only recognizes the first-order object fields.  Intellisense is not provided for nested objects, but the syntax compiles and the correct data is referenced and output by the report generator.

    Accessing child properties in an object data source is also addressed in
    http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/dcbc9d6f-478b-4e3c-b429-bb2ba33f4e3b, http://blogs.msdn.com/tudortr/archive/2006/04/10/NestedObjectsDataSource.aspx, and https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=411823&wa=wsignin1.0, with the latter reference suggesting "For DataSets provided to RDLC files, there is a requirement that the data be flat. Each DataSet needs to be "rectangular" without further levels of grouping."  I have not found this to be the case in my situation since I not using a dataset datasource (I am using custom objects populated via Linq query).

    I am relieved to have finally found the gotreportviewer reference to the appropriate syntax, and hope this research helps someone else.

         -BGood


    Sunday, November 29, 2009 8:52 PM
  • Thanks for the reply BGood

    We are still using RDLC, so have had to flatten the data.

    For what its worth, using LINQ to flatten (denormalise) the entity graph is fairly quick, and the anonymous class output can be provided as the data source.

    (Note that this doesn't help with the designer however - the flattened fields need to be added directly to the XML before dragging & dropping)

    HTH

    Stuart
    Wednesday, February 17, 2010 11:45 AM
  • Good point Stuart.  I hadn't thought about Linq flattening the object hierarchy, but thanks to your post I see that is indeed the case, and probably why what I am doing is working.  Thanks, -BGood
    Wednesday, February 17, 2010 3:53 PM