Skip to main content

Provide a Custom Database Schema

  • 4 minutes to read

After you register connection strings, you can specify tables, views and stored procedures to include in a database schema and display in the Data Source Wizard. You can also specify a custom database schema for report preview.

A custom database schema provider allows you to restrict access to tables, views, stored procedures, and data fields in the Query Builder. Fewer objects improve the operation speed when a report rebuilds the database schema before the data is displayed.

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

    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. Use a custom database schema provider for the Data Source Wizard. Create a custom database schema provider factory (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. Use a custom database schema provider for the report’s preview. You can do one of the following:

  4. To register a custom database schema provider factory for the Data Source Wizard, call the static DefaultReportDesignerContainer.RegisterDataSourceWizardDBSchemaProviderExFactory<T> method at application startup.

    using DevExpress.DataAccess.Web;
    using System;
    using DevExpress.XtraReports.Web.ReportDesigner
    // ...
    
    public class Global_asax : System.Web.HttpApplication {
        void Application_Start(object sender, EventArgs e) {
            // ...                          
            // Register a connection string provider.
            // ...
            // Register the custom provider factory.
            DefaultReportDesignerContainer.RegisterDataSourceWizardDBSchemaProviderExFactory<MyDataSourceWizardDBSchemaProviderFactory>();
        }
        // ...
    }
    
  5. To register a custom database schema provider factory for the report’s preview, call the static DefaultWebDocumentViewerContainer.RegisterDBSchemaProviderExFactory<T> method at application startup. Note that the MyDataSourceWizardDBSchemaProviderFactory class should implement the IDBSchemaProviderExFactory interface.

    using DevExpress.DataAccess.Web;
    using System;
    using DevExpress.XtraReports.Web.ReportDesigner
    // ...
    
    public class Global_asax : System.Web.HttpApplication {
        void Application_Start(object sender, EventArgs e) {
            // ...                          
            // Register a connection string provider.
            // ...
            // Register the custom provider factory.
            DefaultWebDocumentViewerContainer.RegisterDBSchemaProviderExFactory<MyDataSourceWizardDBSchemaProviderFactory>();
        }
        // ...
    }
    

Tip

You can use the MyDataSourceWizardDBSchemaProviderFactory class (defined in step 2) without modifications as a custom database schema provider for the report’s preview. Call the DefaultReportDesignerContainer.RegisterDataSourceWizardDBSchemaProviderExFactory<T>(Boolean) method at application startup with the overrideReportPreviewProvider parameter set to true.

See Also