Binding to EF Data Sources

  • 2 minutes to read

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.


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



    The current page does not contain the Entity Framework data source type by default. 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.


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


    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.


    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");