Skip to main content

XPO Data Source in ASP.NET Core

  • 2 minutes to read

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.

Create an XPO Model

In your application, add a database to the project. In this example, it is nwind.db from the C:\Users\Public\Documents\DevExpress Demos 23.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); }
        }
    }
}

Configure an XPO Data Source

Create a Data Source

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));

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 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:

Web Dashboard - Add XPO Data Source

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.

View Example