Extract Data Source in ASP.NET Core
- 2 minutes to read
Extract Data Source is a compressed snapshot of data from a regular data source.
This data is saved to a local file and can be updated from the original data source at any time.
The extract data file is optimized for data grouping. It reduces the initial dashboard load time.
The Extract Data Source improves performance when a complex query or a stored procedure takes a significant amount of time to get data from a database.
This topic shows how to add the DashboardExtractDataSource to an in-memory data source storage, and make it available to users.
Prepare Data
In your application, add the .dat
file to the Data folder. You can find a sample data extract in the following directory:
C:\Users\Public\Documents\DevExpress Demos 24.2\Components\Data
Configure an Extract Data Source
Create a Data Source
To create an Extract Data Source, follow the steps below:
- Create a DashboardExtractDataSource instance.
- Specify the DashboardExtractDataSource.ConnectionName property to uniquely identify the data connection in code.
- Handle the DashboardConfigurator.ConfigureDataConnection event:
- Specify the ExtractDataSourceConnectionParameters at runtime. For example, set the ExtractDataSourceConnectionParametersBase.FileName property.
- Assign the connection parameters to the e.ConnectionParameters property.
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
using Microsoft.Extensions.FileProviders;
DashboardExtractDataSource extractDataSource = new DashboardExtractDataSource("Extract Data Source");
extractDataSource.Name = "Extract Data Source";
extractDataSource.ConnectionName = "dataExtract";
configurator.ConfigureDataConnection += (s, e) => {
if (e.ConnectionName == "dataExtract") {
ExtractDataSourceConnectionParameters extractParams = new ExtractDataSourceConnectionParameters();
extractParams.FileName = fileProvider.GetFileInfo("Data/EnergyStatistics.dat").PhysicalPath;
e.ConnectionParameters = extractParams;
}
};
Register the Data Source in the Storage
Call the DataSourceInMemoryStorage.RegisterDataSource method to register the data source in the data source storage. Call the DashboardConfigurator.SetDataSourceStorage method to specify the data source storage for the Web Dashboard.
// Create a data source storage.
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Register the Extract data source.
dataSourceStorage.RegisterDataSource("extractDataSource", extractDataSource.SaveToXml());
// Register the storage for the Web Dashboard.
configurator.SetDataSourceStorage(dataSourceStorage);
The Extract Data Source is now available in the Web Dashboard:
Users can now bind dashboard items to data in the Web Dashboard’s UI.
Example: How to Register Data Sources for ASP.NET Core Dashboard Control
The example shows how to make a set of data sources available for users in the Web Dashboard application.