The requested page is not available for the requested platform. You are viewing the content for Default platform.
All docs
V19.2
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Connect the ASP.NET Core Dashboard to an XPO data source

  • 2 min to read

The example below shows how to add the DashboardXpoDataSource to the data source storage and make it available to end users. This example uses XPO Business Model based on the SQLite database.

  1. In your application, create the Data folder and add the nwind.db database to it from the following folder:

    C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data

  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 appsettings.json, provide a connection to the SQLite database.

    {
        //...
        "ConnectionStrings": {
            "NWindConnectionString": "XpoProvider=SQLite;Data Source=Data/nwind.db",            
        }
    }
    
  4. In the Startup.cs file, create a public method that returns a configured in-memory dashboard data source storage (DataSourceInMemoryStorage) and define the XPO data source.

    using DevExpress.DashboardCommon;
    
    public 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 DevExpress.AspNetCore;
    using DevExpress.DashboardAspNetCore;
    using DevExpress.DashboardWeb;
    
    public void ConfigureServices(IServiceCollection services) {            
        services
            .AddMvc()
            .AddDefaultDashboardController(configurator => {
                // ...
                configurator.SetDataSourceStorage(CreateDataSourceStorage());
            });
    }
    
  6. As a result, the XPO Data Source is displayed as a Web Dashboard's predefined data source.

    End users can now bind the dashboard items to data in the Web Dashboard's UI. See Binding Dashboard Items to Data in the Web Dashboard's UI for more information.

Example

The example displays how to provide a Web Dashboard with a set of predefined data sources available for end users.