Skip to main content

XPO Data Source

  • 2 minutes to read

This tutorial shows how to add the DashboardXpoDataSource to an in-memory data source storage, and make it available to users. The XPO Business Model used in this tutorial is based on the SQLite database.

  1. In your application, add the nwind.db database to the App_Data folder from the C:\Users\Public\Documents\DevExpress Demos 24.2\Components\Data directory.

  2. Create an XPO model based on the SQLite nwind.db database.

    using DevExpress.Xpo;
    
    namespace WebDashboardApp {
        [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); }
            }
        }
    }
    
  3. In Web.config, specify a connection string to the SQLite database.

    <configuration>
        <connectionStrings>
            <add name="NWindConnectionString" connectionString="XpoProvider=SQLite;Data Source=|DataDirectory|\nwind.db" />            
        </connectionStrings>
    </configuration>
    
  4. In the dashboard configuration file (for example, DashboardConfig.cs / DashboardConfig.vb), create a public method that returns the configured dashboard’s data source storage (DataSourceInMemoryStorage) and define the XPO data source.

    using System;
    using DevExpress.DashboardCommon;
    using DevExpress.DashboardWeb;
    
    public static DataSourceInMemoryStorage CreateDataSourceStorage() {
        DataSourceInMemoryStorage dataSourceStorage = new DataSourceInMemoryStorage();
    
        DashboardXpoDataSource xpoDataSource = new DashboardXpoDataSource("XPO Data Source");
        xpoDataSource.ConnectionStringName = "NWindConnectionString";
        xpoDataSource.SetEntityType(typeof(Category));
        dataSourceStorage.RegisterDataSource("xpoDataSource", xpoDataSource.SaveToXml());  
    
        return dataSourceStorage;
    }
    
  5. Use the DashboardConfigurator.SetDataSourceStorage method to set the data source storage and pass the created CreateDataSourceStorage method to use the return value as a parameter.

    using System;
    using DevExpress.DashboardWeb;
    using DevExpress.DataAccess.Json;
    
    public static void RegisterService(RouteCollection routes) {
        routes.MapDashboardRoute("dashboardControl", "DefaultDashboard");
    
        // ...
    
        DashboardConfigurator.Default.SetDataSourceStorage(CreateDataSourceStorage());
    }
    

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

The example shows how to make a set of data sources available for users in the Web Dashboard application.

View Example: How to Register Data Sources for the ASP.NET MVC Dashboard Extension