dashboard-114433-winforms-dashboard-winforms-designer-create-dashboards-in-the-winforms-designer-providing-data-entity-framework-data-source-binding-to-ef-data-sources.md
The Dashboard Designer allows you to connect to an Entity Framework data source defined within the current project from an external assembly that contains the required context.
To bind a dashboard to an Entity Framework data source from the current project, do the following:
Click New Data Source in the Data Source ribbon tab.
On the first page of the invoked Data Source Wizard dialog, select Entity Framework and click Next.
On the next page, select the required data context and click Next.
On the next page, specify a connection string used to establish a data connection. The following options are available:
Choose the default connection string if it is specified in the application’s configuration file.
Specify a custom connection string in the connection string editor.
Select an existing connection string available in the current project.
Note
The approach described in this section requires that your project contains an .edmx file that defines a conceptual model. The Code-First approach to calling stored procedures is not supported by DashboardEFDataSource.
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.
Click Add and select the required stored procedures to add to the data source.
Specify the Value passed as a stored procedure parameter. Click the Preview… button to preview data returned by the stored procedure call.
As an alternative, enable the Expression check box to invoke the Expression Editor dialog. In the dialog, you can specify the expression or select an existing dashboard parameter to use it as a stored procedure parameter.
On the last page, you can apply filter criteria to the resulting query. Click Finish to create the data source.
The data source fields are displayed in the Data Source Browser:
To create an Entity Framework data source in code, create an instance of the DashboardEFDataSource class and specify the following properties:
Add the created DashboardEFDataSource object to the Dashboard.DataSources collection.
The following code snippet shows how to create an Entity Framework data source and add it to the collection of dashboard data sources:
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.EntityFramework;
// ...
Dashboard dashboard = new Dashboard();
DashboardEFDataSource efDataSource = new DashboardEFDataSource();
efDataSource.ConnectionParameters = new EFConnectionParameters(typeof(SalesPersonModel), "SalesPersonModel");
efDataSource.Fill();
dashboard.DataSources.Add(efDataSource);
Imports DevExpress.DashboardCommon
Imports DevExpress.DataAccess.EntityFramework
' ...
Private dashboard As New Dashboard()
Private efDataSource As New DashboardEFDataSource()
efDataSource.ConnectionParameters = New EFConnectionParameters(GetType(SalesPersonModel), "SalesPersonModel")
efDataSource.Fill()
dashboard.DataSources.Add(efDataSource)