Skip to main content

Register a Custom Schema Provider for a Synonym Database

  • 4 minutes to read

This document describes how to implement a custom data source schema provider that enables end-users to bind reports to a synonym database.

Tip

A synonym is a database object that provides an alternative name for another database object.

Refer to the Oracle and Microsoft SQL Server documentation to learn how different database engines support synonyms.

Implement a Custom Schema Provider

The following code shows how to create a custom database schema provider inherited from the DBSchemaProviderEx class that is the IDBSchemaProviderEx interface’s default implementation.

using DevExpress.DataAccess.Sql;
using DevExpress.Xpo.DB;
using System.Collections.Generic;
using System.Linq;
// ...

public class SynonymDBSchemaProvider : DevExpress.DataAccess.Sql.DBSchemaProviderEx {
    public override DBTable[] GetTables(SqlDataConnection connection, params string[] tableList) {
        List<DBTable> tables = base.GetTables(connection, tableList).ToList();
        if(connection.Name == "OracleConnection")
            tables.Add(new DBTable("Regions") {
                Columns = {
                    new DBColumn { Name = "REGION_ID", ColumnType = DBColumnType.Int32 },
                    new DBColumn { Name = "REGION_NAME", ColumnType = DBColumnType.String, Size = 25 },
                }
            });

        return tables.ToArray();
    }
}

Register the Schema Provider in a WinForms Reporting Application

The following code registers a custom database schema provider in a WinForms End-User Report Designer by calling the XRDesignMdiController.AddService method.

using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UserDesigner;
// ...

public partial class Form1 : XRDesignRibbonForm {
    public Form1() {
        InitializeComponent();
        DesignMdiController.AddService(typeof(IDBSchemaProviderEx), new SynonymDBSchemaProvider());
    }
}

Register the Schema Provider in a WPF Reporting Application

The following code registers a custom database schema provider in a WPF End-User Report Designer.

<Window x:Class="CustomDBSchemaProviderEx.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:CustomDBSchemaProviderEx"
        xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner" 
        xmlns:dxda="http://schemas.devexpress.com/winfx/2008/xaml/dataaccess" 
        xmlns:dasql="clr-namespace:DevExpress.DataAccess.Sql;assembly=DevExpress.DataAccess.v18.1" 
        Title="MainWindow" >

    <dxrud:ReportDesigner HorizontalAlignment="Left" VerticalAlignment="Top">
        <dxrud:ReportDesigner.ServicesRegistry>
            <dxda:InstanceEntry ServiceType="{x:Type dasql:IDBSchemaProviderEx}" >
                <dxda:InstanceEntry.Instance>
                    <local:SynonymDBSchemaProvider />
                </dxda:InstanceEntry.Instance>
            </dxda:InstanceEntry>
        </dxrud:ReportDesigner.ServicesRegistry>
    </dxrud:ReportDesigner>

</Window>

Register the Schema Provider in an ASP.NET Reporting Application

Create a custom database schema provider factory by implementing the IDataSourceWizardDBSchemaProviderExFactory interface as shown below. Use the IDataSourceWizardDBSchemaProviderExFactory.Create method to initialize a new custom data store schema provider (SynonymDBSchemaProvider).

using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.Web;
// ...

public class MyDataSourceWizardDBSchemaProviderFactory : IDataSourceWizardDBSchemaProviderExFactory {
    public IDBSchemaProviderEx Create() {
        return new SynonymDBSchemaProvider();
    }
}

ASP.NET Application

Register the custom database schema provider factory by calling the static DefaultReportDesignerContainer.RegisterDataSourceWizardDBSchemaProviderExFactory<T> method, as shown below.

using DevExpress.DataAccess.Web;
using System;
// Add a reference to the DevExpress.XtraReports.Web assembly
using DevExpress.XtraReports.Web.ReportDesigner
// ...

public class Global_asax : System.Web.HttpApplication {
    void Application_Start(object sender, EventArgs e) {
        // ...
        // Register the custom provider factory.
        DefaultReportDesignerContainer.RegisterDataSourceWizardDBSchemaProviderExFactory<MyDataSourceWizardDBSchemaProviderFactory>();
    }
    // ...
}

ASP.NET Core Application

Register the custom database schema provider factory by calling the RegisterDataSourceWizardDBSchemaProviderExFactory<T>() method, as shown below.

using DevExpress.AspNetCore;
using DevExpress.AspNetCore.Reporting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDevExpressControls();
builder.Services.ConfigureReportingServices(configurator => {
    configurator.ConfigureQueryBuilder(queryBuilderConfigurator => {
        // Register the custom provider factory.
        queryBuilderConfigurator.RegisterDataSourceWizardDBSchemaProviderExFactory<MyDataSourceWizardDBSchemaProviderFactory>();
    });
});

var app = builder.Build();