Ticket T800938
Visible to All Users

XtraReports with Entity Framework data source: set DS at runtime

created 6 years ago

Hi,
I've created a XtraReport with two EntityServerModeSources (see attached screenshot).
The data to be shown must be set by the calling form. How can I do this?

The code in the form is so far:

C#
// create report xrComputer xrc = new xrComputer(); // set data source xrc.Datasource = ??? // show report xFrmReportViewer frm = new xFrmReportViewer { documentViewer = { DocumentSource = xrc } }; frm.ShowDialog(this);

Best regards, Tom

Answers approved by DevExpress Support

created 6 years ago (modified 6 years ago)

Hello,
Our reports don't support the Server mode and we recommend binding a report to the EFDataSource component as illustrated in the How to: Bind a Report to an Entity Framework Data Source help topic. Check the code behind of the Default.aspx.cs file from the How to provide ASPxReportDesigner with the SqlDataSource, ObjectDataSource and EFDataSource at runtime Code Example where you'll find methods demonstrating runtime initialization of the EFDataSource component.

However if the EntityServerModeSource component is more suitable for you, the following code-snippet illustrates how to change a connection for this component at runtime:

C#
NorthwindEntities entity = new NorthwindEntities(); XtraReport1 report = new XtraReport1(); EntityServerModeSource source = report.DataSource as EntityServerModeSource; source.QueryableSource = entity.Categories; source.KeyExpression = "CategoryID"; reportDesigner1.OpenReport(report);

    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.