The requested page is not available for the requested platform. You are viewing the content for Default platform.

Provide a Custom Database Schema

After you registered connection strings, you can specify tables, views and stored procedures to include in a database schema and display in the SQL Data Source Wizard.

  1. Implement the IDBSchemaProviderEx interface to create a custom database schema provider (named MyDBSchemaProvider) as shown below.

    using DevExpress.DataAccess.Sql;
    using DevExpress.Xpo.DB;
    using System.Linq;
    // ...
    
    public class MyDBSchemaProvider : IDBSchemaProviderEx {
        DBSchemaProviderEx provider;
        public MyDBSchemaProvider() {
            this.provider = new DBSchemaProviderEx();
        }
    
        public DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) {
            return provider.GetTables(connection, tableList)
                .Where(table => table.Name.StartsWith("C"))
                .ToArray();
        }
    
        public DBTable[] GetViews(SqlDataConnection connection, params string[] viewList) {
            return provider.GetViews(connection, viewList)
                .Where(view => view.Name.StartsWith("Order"))
                .ToArray();
        }
    
        public DBStoredProcedure[] GetProcedures(SqlDataConnection connection, params string[] procedureList) {
            return provider.GetProcedures(connection, procedureList)
                .Where(storedProcedure => storedProcedure.Arguments.Count == 0)
                .ToArray();
        }
    
        public void LoadColumns(SqlDataConnection connection, params DBTable[] tables) {
            provider.LoadColumns(connection, tables);
        }
    }
    
  2. Create a custom database schema provider factory (named MyDataSourceWizardDBSchemaProviderFactory). Implement the IDataSourceWizardDBSchemaProviderExFactory interface and create a new custom data store schema provider (MyDBSchemaProvider) in the IDataSourceWizardDBSchemaProviderExFactory.Create method.

    using DevExpress.DataAccess.Sql;
    using DevExpress.DataAccess.Web;
    // ...
    
    public class MyDataSourceWizardDBSchemaProviderFactory : IDataSourceWizardDBSchemaProviderExFactory {
        public IDBSchemaProviderEx Create() {
            return new MyDBSchemaProvider();
        }
    }
    
  3. Register the custom database schema provider factory at the application's startup. Call one of the ServiceCollectionServiceExtensions class's method depending on the service's lifetime (the AddTransient method in this example).

    using Microsoft.Extensions.DependencyInjection;
    using DevExpress.AspNetCore;
    using DevExpress.AspNetCore.Reporting;
    // ...
    
    public class Startup {
        // ...
        public void ConfigureServices(IServiceCollection services) {
            // ...
            services.AddTransient<IDataSourceWizardDBSchemaProviderExFactory, MyDataSourceWizardDBSchemaProviderFactory>();
        }
    }
    
See Also