Back to Devexpress

SqlDataSource.Relations Property

corelibraries-devexpress-dot-dataaccess-dot-sql-dot-sqldatasource-3826e8ab.md

latest3.2 KB
Original Source

SqlDataSource.Relations Property

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

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
[LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)]
public MasterDetailInfoCollection Relations { get; }
vb
<LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)>
Public ReadOnly Property Relations As MasterDetailInfoCollection

Property Value

TypeDescription
MasterDetailInfoCollection

A MasterDetailInfoCollection object.

|

Remarks

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

csharp
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"));
}
vb
Imports DevExpress.DataAccess.Sql
Imports DevExpress.DataAccess.ConnectionParameters
' ...
Private Sub AddQueryRelations()
    Dim categories As SelectQuery = SelectQueryFluentBuilder.
        AddTable("Categories").
        SelectAllColumns().Build("Categories")
    Dim products As SelectQuery = SelectQueryFluentBuilder.
        AddTable("Products").
        SelectAllColumns().Build("Products")

    DataSource.Queries.AddRange(New SqlQuery() { categories, products })
    DataSource.Relations.Add(New MasterDetailInfo("Categories", "Products", "CategoryID", "CategoryID"))
End Sub

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

SqlDataSource Class

SqlDataSource Members

DevExpress.DataAccess.Sql Namespace