How to: Hide Data Tables in the Database Schema

The following example shows how to use the IDBSchemaProviderEx service to hide specific data tables in the SnapControl so that end users cannot see them in the Query Builder.

Follow the steps below to implement a custom database schema provider:

  1. Create a DBSchemaProviderEx class descendant. Override the DBSchemaProviderEx.GetTables method to exclude the desired table from the schema, as shown below:

    using DevExpress.DataAccess.Sql;
    using DevExpress.Xpo.DB;
    public class MyDBSchemaProvider : DBSchemaProviderEx
            public override DBTable[] GetTables(SqlDataConnection connection, params string[] tableList)
                List<DBTable> list = new List<DBTable>(base.GetTables(connection, tableList));
                list.Remove(list.Where(x => x.Name.Equals("Customers")).FirstOrDefault());
                return list.ToArray();
  2. In the Form.Load event handler, register the created database schema provider using the AddService method:

    private void Form1_Load(object sender, EventArgs e)
          snapControl1.AddService(typeof(IDBSchemaProviderEx), new MyDBSchemaProvider());

The image below shows the result. The Customers data table is hidden from the table list in the Query Builder.