Ticket T382175
Visible to All Users

XtraReport using multiple entities in an EF 6 model

created 9 years ago

Hello,

I'm learning the XtraReports system for a ASP.NET web site.  I use Entity Framework 6 for my SQL Server datastore and have been having trouble building a report that uses multiple entities in the DataSource.  I set the DataSource to the EF component but leave the DataMember blank as I'm not tying to a single entity in the model which has 23 entities (tables).  I dragged Entity1.Field1 to my Detail section and ran the report, the data that appeared was not correct and I'm not sure why, I have no idea what it was showing.  If I set the DataMember on the report to Entity1 and then use Field1 it will show correctly.

Now what I need to do is build a report such that the header has fields from Entity12 and the detail has fields from Entity1, Entity2 etc.  Is this possible? How can I build a report that is not tied to a single EF entity assigned in the DataMember property of the report?  I also don't want to have to create a new EF component for each entity, I can also use a SQL Server datasource if needed and that's fine and would like to know how to do the same using that as a data source, building a single report from multiple tables.

Thank you

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hi Neal,

There are several ways to bind your report to data selected from your EF model. The simplest way to do that is to use the EFDataSource component, as demonstrated in the How to: Bind a Report to an Entity Framework Data Source help topic.In this case, use the DataMember property of your report to specify which table/view you would like to use to bind the report to data. But, this data source does not provide server-side filtering functionality, and you cannot perform complex LINQ queries to your EF model.
Alternatively use the approach demonstrated in the Binding a Report to Lists help topic to bind your report to data selected at runtime from your EF model and converted to IList. In this case, use the ObjectDataSource component to bind your report to the required class schema at design time as demonstrated in the  How to: Bind a Report to an Object Data Source help topic. Note that in the case of binding your report to IList, it is not necessary to specify the report's DataMember property value (that's because the IList does not have multiple data members). This approach is demonstrated in the How to create a master-detail report bound to an ORM (Entity Framework) model in MVC applications MVC code example.

    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.