Skip to main content

Use the Query Builder Light Mode

  • 3 minutes to read

The Query Builder Light mode allows you to specify custom names for tables and columns. The Query Builder does not display the resulting SQL query and disables column expressions in this mode because these options use actual data member names.

This document describes how to enable the Query Builder Light mode and customize table and column names in it.

Enable the Query Builder Light Mode

Set the QueryBuilderLight property to true to enable the Query Builder Light mode (for instance, in the Window’s Loaded event handler).

using DevExpress.Xpf.DataAccess.DataSourceWizard;
//... 

private void Window_Loaded(object sender, RoutedEventArgs e) {
    //...
    reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = true;
    //...
}

Alternatively, you can use the following XAML code to enable this mode.

<Window ...
        xmlns:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner"
        xmlns:dxda="http://schemas.devexpress.com/winfx/2008/xaml/dataaccess">

    <dxrud:ReportDesigner x:Name="reportDesigner">
        <dxrud:ReportDesigner.DataSourceWizardSettings>
            <dxda:DataSourceWizardSettings SqlWizardSettings="{dxda:SqlWizardSettings QueryBuilderLight=True}" />
        </dxrud:ReportDesigner.DataSourceWizardSettings>
    </dxrud:ReportDesigner>
</Window>

This image illustrates the result.

Query Builder: Light Mode

Customize Table and Column Names

The Query Builder Light mode allows you to implement the IDisplayNameProvider interface to customize table and column names.

This example demonstrates how to add a space to table or column names in the IDisplayNameProvider.GetFieldDisplayName method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Data;
//...

public partial class MainWindow : Window
{
//...
    private void Window_Loaded(object sender, RoutedEventArgs e) {
        // Enable the Query Builder Light mode.
        reportDesigner.DataSourceWizardSettings.SqlWizardSettings.QueryBuilderLight = true;

        // Register the customization service type.
        reportDesigner.ServicesRegistry.Add(new TypeEntry() { ServiceType = typeof(IDisplayNameProvider), ConcreteType = typeof(DisplayNameProvider) });
    }
}

class DisplayNameProvider : IDisplayNameProvider {
    // Substitute the default data source name
    // with a custom one.
    public string GetDataSourceDisplayName() {
        return "Northwind Traders";
    }

    public string GetFieldDisplayName(string[] fieldAccessors) {
        // Get a field or table name from the data source.
        string fieldName = fieldAccessors[fieldAccessors.Length - 1];

        // Insert spaces between words in a field name.
        return ChangeNames(fieldName);
    }

    public string ChangeNames(string name) {
        string result = string.Empty;
        bool isPrevLow = false;

        foreach (char symb in name) {
            // Check if a character is uppercase.
            // Check if the previous character is uppercase 
            // to avoid spaces inside abbreviations.
            if (Char.IsUpper(symb) && isPrevLow) {
                result += " " + symb;
            }
            else {
                result += symb;
            }
            isPrevLow = Char.IsLower(symb);
        }
        return result;
    }
//...
}

The following image illustrates customization results: