corelibraries-devexpress-dot-dataaccess-dot-sql-dot-sqldatasource-3826e8ab.md
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
[LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)]
public MasterDetailInfoCollection Relations { get; }
<LocalizableCategory(DataAccessStringId.PropertyGridDataCategoryName)>
Public ReadOnly Property Relations As MasterDetailInfoCollection
| Type | Description |
|---|---|
| MasterDetailInfoCollection |
A MasterDetailInfoCollection object.
|
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"));
}
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