Skip to main content

SqlDataSource.Relations Property

Provides access to the collection of master-detail relations of the SqlDataSource.

Namespace: DevExpress.DataAccess.Sql

Assembly: DevExpress.DataAccess.v24.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

[LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)]
public MasterDetailInfoCollection Relations { get; }

Property Value

Type Description
MasterDetailInfoCollection

A MasterDetailInfoCollection object.

Remarks

To add a relationship between two tables, add a MasterDetailInfo instance to the SqlDataSource.Relations collection:

using DevExpress.DataAccess.Sql;
using DevExpress.DataAccess.ConnectionParameters;
// ...
void AddQueryRelations()
{
    SelectQuery categories = SelectQueryFluentBuilder
        .AddTable("Categories")
        .SelectAllColumns()
        .Build("Categories");
    SelectQuery products = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectAllColumns()
        .Build("Products");

    DataSource.Queries.AddRange(new SqlQuery[] { categories, products });
    DataSource.Relations.Add(
        new MasterDetailInfo("Categories", "Products", "CategoryID", "CategoryID"));
}

For more information, review the following help topic: Manage Table Relations.

The full code is available in the sample application:

View Example: How to Create a Report Bound to the SQL Data Source

See Also