dashboard-401226-web-dashboard-integrate-dashboard-component-dashboard-backend-prepare-data-source-storage-for-the-aspnet-core-framework-xpo-data-source.md
This topic shows how to add the DashboardXpoDataSource to an in-memory data source storage, and make it available to users. This example uses an XPO Business Model based on the SQLite database.
In your application, add a database to the project. In this example, it is nwind.db from the C:\Users\Public\Documents\DevExpress Demos 25.2\Components\Data directory.
In appsettings.json, specify a connection string to the SQLite database:
{
//...
"ConnectionStrings": {
"NWindConnectionString": "XpoProvider=SQLite;Data Source=Data/nwind.db",
}
}
Create an XPO model based on the SQLite nwind.db database:
using DevExpress.Xpo;
namespace WebDashboardDataSources {
[Persistent("Categories"), DeferredDeletion(false)]
public class Category: XPCustomObject {
int categoryId;
string categoryName;
string description;
[Key]
public int CategoryID {
get { return categoryId; }
set { SetPropertyValue<int>("CategoryID", ref categoryId, value); }
}
public string CategoryName {
get { return categoryName; }
set { SetPropertyValue<string>("CategoryName", ref categoryName, value); }
}
public string Description {
get { return description; }
set { SetPropertyValue<string>("Description", ref description, value); }
}
}
}
To define an XPO Data Source, follow the steps below:
using DevExpress.DashboardCommon;
using DevExpress.DashboardWeb;
DashboardXpoDataSource xpoDataSource = new DashboardXpoDataSource("XPO Data Source");
xpoDataSource.ConnectionStringName = "NWindConnectionString";
xpoDataSource.SetEntityType(typeof(Category));
Call the DataSourceInMemoryStorage.RegisterDataSource method to register the data source in the data source storage. Call the DashboardConfigurator.SetDataSourceStorage to specify the data source storage for the Web Dashboard.
// Create a data source storage.
DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
// Register the XPO data source.
dataSourceStorage.RegisterDataSource("xpoDataSource", xpoDataSource.SaveToXml());
// Register the storage for the Web Dashboard.
configurator.SetDataSourceStorage(dataSourceStorage);
The XPO Data Source is now available in the Web Dashboard:
Users can 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.