How to: Bind the Web Dashboard to Entity Framework
- 2 minutes to read
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:
Create the DashboardEFDataSource object instance and pass the typeof(NorthwindDataModel) to the EFDataSource.ConnectionParameters property.
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.
Run the application and create a new dashboard.
The SalesPerson data source is now available in the data source list.