The requested page is not available for the requested platform. You are viewing the content for Default platform.

How to: Bind the Web Dashboard to Entity Framework

This tutorial demonstrates how to create the Entity Framework data source and add it to the Web Dashboard data source list.

For example, your project already contains the NorthwindDataModel context that provides access to data:

//...
    using System.Data.Entity;

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

        public virtual DbSet<SalesPerson> SalesPersons { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //...
        }
    }

To create a data source based on this context, do the following:

  1. Create the DashboardEFDataSource object instance and pass the typeof(NorthwindDataModel) to the EFDataSource.ConnectionParameters property.

    using DevExpress.DashboardCommon;
    using DevExpress.DataAccess.EntityFramework;
    
    //...
    DashboardEFDataSource efDataSource = new DashboardEFDataSource("SalesPerson");
    efDataSource.ConnectionParameters = new EFConnectionParameters(typeof(NorthwindDataModel));
    
  2. Create the in-memory data source storage (DataSourceInMemoryStorage) and use the DataSourceInMemoryStorage.RegisterDataSource method to register the data source in the created storage.

    using DevExpress.DashboardWeb;
    
    //...
    DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
    dataSourceStorage.RegisterDataSource(efDataSource.SaveToXml());
    ASPxDashboard1.SetDataSourceStorage(dataSourceStorage);
    

    See Register Default Data Sources to learn more about registering default data sources.

  3. Run the application and create a new dashboard.

    WebDesignerGettingStarted_CreateDashboard_dx

    The SalesPerson data source is now available in the data source list.

See Also