Binding to EF Data Sources

The Dashboard Designer allows you to connect to an Entity Framework data source defined within the current project from an external assembly containing the required context.

Creating a Data Source in the Data Source Wizard

To bind a dashboard to an Entity Framework data source from the current project, do the following.

  1. Click the New Data Source button in the Data Source ribbon tab.

    DataBinding_NewDataSource

  2. On the first page of the invoked Data Source Wizard dialog, select Entity Framework and click Next.

    DataSourceWizard_DataSourceType_EF

    Important

    By default, the current page does not contain the Entity Framework data source type. To customize the list of displayed data source types, use the DashboardDesignerDataSourceWizardSettings.AvailableDataSourceTypes property.

  3. On the next page, select the required data context and click Next.

    ChooseDataContextPage

  4. On the final page, choose the connection string corresponding to the selected data context and click Finish.

    EF_SelectConnectionString

    If the application configuration file does not contain the required connection string, or you need to specify the connection string manually, select No, specify a custom connection string and click Next.

    EF_CustomConnectionString

    On this page, specify a custom connection string and click Finish.This creates the data source and displays its fields in the Data Source Browser.

Creating a Data Source in Code

To create an Entity Framework data source in code, create an instance of the DashboardEFDataSource class and specify the following properties.

  • Specify the connection parameters using the EFDataSource.ConnectionParameters property. The EFConnectionParameters object returned by this property allows you to specify the type of an Entity Framework context used to connect to data, the connection string or use the data context from the external assembly.
  • Use the EFDataSource.Fill method to retrieve data from the data source.

Finally, 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);