All docs
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Entity Framework Data Source in ASP.NET Web Forms

  • 4 minutes to read

This topic shows how to add the DashboardEFDataSource to an in-memory data source storage, and make it available to users.

DashboardEFDataSource supports the following Entity Framework versions:

  • Entity Framework 5.0 and higher.
  • Entity Framework Core 1.0 and higher.

Specify a Database Connection

Specify a connection to the database in Web.config.

In this example, the connection name is OrdersContext. The connection supplies the dashboard with data from the MS SQL Server database file (NWind.mdf). You can find this database in the C:\Users\Public\Documents\DevExpress Demos 21.2\Components\Data directory.

    <add name="OrdersContext" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\NWind.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

The Web Dashboard supports the following data providers: Custom Connection Strings for Data Sources.

Create an ADO.NET Entity Data Model

  1. Right-click the project and select Add → New Item…. In the opened dialog, select ADO.NET Entity Data Model.

  2. Specify OrdersContext as the model name and select the Code First from database model type in the invoked wizard.

  3. Select the added OrdersContext string as a data connection for the created model.

  4. On the next page, specify which tables and views to include in your model.

Note that the Entity Framework context class should be public.

In this tutorial, the data model is based on the OrderDetail table. The code below shows the generated data model.


namespace WebFormsDashboardDataSources {
    using System.Data.Entity;

    public partial class OrdersContext: DbContext {
        public OrdersContext()
            : base("name=OrdersContext") {

        public virtual DbSet<OrderDetail> OrderDetails { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder) {
                .Property(e => e.UnitPrice)
                .HasPrecision(10, 4);

Visual Basic:

Imports System.Data.Entity

Namespace WebFormsDashboardDataSources

    Public Partial Class OrdersContext
        Inherits DbContext

        Public Sub New()
        End Sub

        Public Overridable Property OrderDetails As DbSet(Of OrderDetail)

        Protected Overrides Sub OnModelCreating(ByVal modelBuilder As DbModelBuilder)
            modelBuilder.Entity(Of OrderDetail)().Property(Function(e) e.UnitPrice).HasPrecision(10, 4)
        End Sub
    End Class
End Namespace

Register an Entity Framework Data Source

For example, your ASPX page contains the ASPxDashboard control which unique identifier is ASPxDashboardEf:

<!DOCTYPE html>

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <div style="position: absolute; top: 0; bottom: 0; left: 0; right: 0">
            <dx:ASPxDashboard ID="ASPxDashboardEf" runat="server" Width="100%" Height="100%">

You can define the Entity Framework Data Source in the code-behind page that has the .aspx.cs or .aspx.vb extension depending on the language used:


A code-behind page is one of the variants where you can register the data sources. For example, you can also register them in the Global.asax.cs (Global.asax.vb) file.

using System;
using System.Web.Hosting;
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.EntityFramework;

namespace WebFormsDashboardDataSources.Pages {
    public partial class EFDashboard : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
        // ...
            // Create a data source storage.
            DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();

            // Register an Entity Framework data source.
            DashboardEFDataSource efDataSource = new DashboardEFDataSource("EF Core Data Source");
            efDataSource.ConnectionParameters = new EFConnectionParameters(typeof(OrdersContext));
            dataSourceStorage.RegisterDataSource("efDataSource", efDataSource.SaveToXml());

            // Set the configured data source storage.

            ASPxDashboardEf.InitialDashboardId = "dashboardEf";

The EF Core Data Source is now available in the Web Dashboard:


Users can now bind dashboard items to data in the Web Dashboard’s UI.


The example shows how to make a set of data sources available for users in the Web Dashboard application.


View Example: How to Register Data Sources for ASP.NET Web Forms Dashboard Control