Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Bind a Report to an Entity Framework Data Source

  • 4 minutes to read

This document describes how to use an Entity Framework data source to bind a report to data supplied by an Entity Framework data context at design time within Visual Studio.

To bind a report to an Entity Framework data context, do the following:

#Add Data Context to Your Project

Add a project containing your DBContext definition to your current reporting solution.

Rebuild the project before running the Wizard. Otherwise, the EF data context classes may not be available in the Report Wizard.

#Select a Data Source and Specify Data Context

Open a report (a C#/VB file) in the Visual Studio Report Designer and click the report’s smart tag. In the invoked actions list, expand the drop-down menu for the DataSource property and click Add Report Data Source….

how-to-ef-datasource01

In the invoked Data Source Wizard, select a new data connection. On the next page, select Entity Framework as a connection type and click Next.

ReportWizard-SelectDataSourceType-EntityFramework

On the next page, select the data context. The page displays the data context from the current project assembly.

  • For .NET apps, data context selection from a custom assembly in the Visual Studio Report Designer is not available. DBContext can only be a part of your solution.
  • For .NET Framework apps, you can select a data context from a custom assembly. To do so, use the Browse button on the Choose a data context Data Source Wizard’s page.

The image below illustrates how the page looks for .NET apps:

how-to-ef-datasource03

Click Next to proceed.

Note

In the End-User Report Designer, you can also select a data context from a custom assembly. To display the Browse button and to select a data context from a custom assembly, set the EFWizardSettings.ShowBrowseButton property to true. To learn more, see Data Access Security.

#Select Data from the Database

On the next page, specify a connection string used to establish a data connection. The following options are available:

#Default Connection String

Choose the default connection string if it is specified in the application’s configuration file.

EF default connection string

#Custom Connection String

Specify a custom connection string in the connection string editor and choose whether to store the string in the application’s configuration file.

how-to-ef-datasource-specify-connection-string

See Connection Strings in the ADO.NET Entity Framework for more information.

Note

When you specify a custom connection string in the Data Source wizard, the password is obscured with asterisk characters (the number of characters does not correspond to the actual length of the password). To learn more, see Data Access Security.

#Predefined Connection String

Select an existing connection string available in the current project.

how-to-ef-datasource05

Note

For .NET projects, install Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Json to obtain a data connection string from appsettings.json when you select a predefined data connection in the Data Source Wizard.

#Add Stored Procedures (Optional)

The next wizard page is available only if the current entity data model contains stored procedures. This page allows you to add stored procedures to the data source and configure their parameters.

how-to-ef-datasource06

Refer to the following topic for more information on how to bind a report to a stored procedure: Bind a Report to an Entity Framework Stored Procedure.

#Apply Filter Criteria

On the last page, you can apply filter criteria to the resulting query. Click Finish to create the data source.

EF apply filter criteria

Refer to the following topic for more information on how to access Entity Framework data source filter collection in code: Filter an Entity Framework Data Source.

#Result

The newly created data source will be displayed in the Data Source node of the Report Explorer. Additionally, the hierarchy of the data source will be reflected by the Field List.

how-to-ef-datasource07

See Also