Ticket T699564
Visible to All Users

EFDataSource Not Bringing Children or Related Entities

created 6 years ago

I have an EF context with four Entities in it, SaleGroup, SaleDepartment, SaleText & Tax. Now SaleGroup can have a collection of SaleDepartments, a SaleDepartment can have a Tax and a collection of SalesText.

When I request a collection of SaleGroups from the context I get all child records. However, when I have the Report do this it is only returning the SaleGroups, and no child collections, the SQL profiler confirms this with the TSQL generated.

The Report Designer looks mighty fine, it creates a detail based on SaleGroup and then another detail that is based on SaleGroup.SaleDepartment and another detail that is based on SaleGroup.SaleDepartment.SaleText.

Is what I'm trying to achieve possible, as from the Report Designer it looks likely, or am I going about this totally the wrong way?

I have tried a new report and thrown an object at it, which then works fine at runtime but the preview doesn't, any idea why the preview doesn't or is that just not possible for an object?

Ta.

Show previous comments (5)

    I'm not getting errors as such when using the EFDataSource, I'm just not getting the related child records.

    So investigating this further I have decided that I'm probably better using an ObjectDataSource and using my context the retrieve all necessary data from SQL in one swoop and have the Report use the collection returned, and can confirm that this works in the scenario I tried.

    One final question based on ObjectDataSource if I may is, the 'actual' data retrieved, if it is coming from a context then I take it the data shown on the preview of the report designer is 'design time data' rather than actual data, which is then returned from a constructor which the report can then call?

    Colin.

    Yaroslav (DevExpress Support) 6 years ago

      >>then I take it the data shown on the preview of the report designer is 'design time data' rather than actual data
      This depends on how your ObjectDataSource is set up. For example, if you're binding to a method of some static helper class, this method will be called when you switch to the preview tab (meaning you'll see all the expected live data there). At design time, the schema that you see in the Field List window will be obtained by the means of Reflection. To see what possible ObjectDataSource configurations exist, see How to create Data Access Library data sources at runtime

      P.S. Don't try to preview live data right in the Visual Studio Report Designer, as this won't work. While EFDataSource does a lot of heavy lifting to instantiate DBContext at design time, there is nothing similar for ObjectDataSource. As for EFDataSource, do you think it will be possible to create a small demo for us illustrating the issue? Although I understand that you have a working workaround, I'm still concerned why it doesn't fetch related navigation properties as it's supposed to.
      Thank you for your time and cooperation in advance.

      Regards,
      Yaroslav

        Please see the attachment, I have reproduced it in a sample app with sample database attached as well (You'll have to add the entity framework 6.2 nuget to make it work). You'll will probably need to update the connection string. You'll notice that there is one SaleGroup with two SaleDepartments and one of the SaleDepartments has a couple of SaleTexts, but when you run it only the SaleGroup will show.

        Answers approved by DevExpress Support

        created 6 years ago (modified 6 years ago)

        Hi Colin,
        Thank you for your sample project, it was very helpful. It appears the issue is in your data model: you need to define all navigation properties with the 'virtual' modifier. Please check the following StackOverflow thread to learn about the reason behind this requirement: Why Navigation Properties are virtual by default in EF

        Regards,
        Yaroslav

          Comments (2)

            Ah ha, thanks, that did the trick. However, we stopped using virtual ages ago in our app, but that's fine because we now have options, we can use the EFDataSource and use 'new' ReportEntityViewModels using virtual or we can use our own services to retrieve the data back as an Object and set this as the ObjectSource. Always good to have options.

            Thanks Yaroslav, your help has been truly appreciated.

            Colin.

            Yaroslav (DevExpress Support) 6 years ago

              My pleasure, Colin! I moved my previous reply to the "Answers" section of this thread. Accepting it as a solution will automatically close the ticket as resolved.
              Should there be further questions, feel free to contact us at any time.

              Regards,
              Yaroslav

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.