DashboardFederationDataSource Class
A federated data source that retrieves data from different data sources.
Namespace: DevExpress.DashboardCommon
Assembly: DevExpress.Dashboard.v24.1.Core.dll
NuGet Package: DevExpress.Dashboard.Core
Declaration
public class DashboardFederationDataSource :
FederationDataSourceBase,
IDashboardDataSource,
IDashboardComponent,
IComponent,
IDisposable,
ISupportInitialize,
ISupportPrefix,
IDashboardDataSourceInternal,
ICloneable<DashboardFederationDataSource>,
IAssignable<DashboardFederationDataSource>,
IQueryDataSource<QueryNode>,
IExternalSchemaConsumer
Remarks
The DashboardFederationDataSource
class is a federated data source that integrates different data sources and provides uniform data access with a federated query. You can create a federated data source if a dashboard contains at least one data source. A federated data source does not support OLAP data sources.
Note
In Async mode, if the FederationDataSource includes the DashboardObjectDataSource, make sure that the DashboardObjectDataSource gets data in the AsyncDataLoading event handler and do not call the DashboardObjectDataSource.Fill and FederationDataSource.Fill methods.
You can create federated queries of the following types:
- Join
- Combines rows from two or more sources based on a clause. In code, create a SelectNode instance.
- Union and Union All
- The Union query combines rows from two or more sources into one data set and removes duplicate rows in the merged source. The UnionAll query does the same, except it doesn’t remove duplicated rows. You can create a union query for data sources if data types of their columns are implicitly converted. In code, create a UnionNode instance and specify UnionNode.Type as Union/UnionAll.
- Transformation
- If a data source contains a complex column (an object), you can transform its properties to display them as separate columns in a flattened view. If one of the data columns is an array, you can unfold its values and display a new data row for every element of the array. When you unfold the column, you can flatten it and create a flattened view. In code, create a TransformationNode instance.
Example
This example demonstrates how to bind a dashboard to a federated data source created at runtime. The following data sources are used to create the Data Federation:
- SQL data source connected to the SQLite database
- Excel data source
- Object data source
- JSON Data Source
The example demonstrates the following query types you can use to federate existing data sources:
- Join
- Union and UnionAll
- Transformation
Add the created DashboardFederationDataSource instance to the Dashboard.DataSources collection. The data source obtains its data from federated queries contained in the Queries collection.
Create Join Query Type
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.DataFederation;
using DevExpress.XtraEditors;
// ...
namespace DataFederationExample {
public partial class Form1 : XtraForm {
// ...
private static DashboardFederationDataSource CreateFederatedDataSourceJoin(DashboardSqlDataSource sqliteDataSource, DashboardExcelDataSource exceldataSource, DashboardObjectDataSource objectDataSource) { DashboardFederationDataSource federationDS = new DashboardFederationDataSource("Federated Data Source (JOIN)");
Source sqlSource = new Source("sqlite", sqliteDataSource, "SQLite Orders");
Source excelSource = new Source("excel", exceldataSource, "");
Source objectSource = new Source("object", objectDataSource, "");
#region Use API to join SQL, Excel, and Object Data Sources in a Query
SelectNode mainQueryCreatedByApi = new SelectNode();
mainQueryCreatedByApi.Alias = "FDS-Created-by-API";
SourceNode sqlSourceNode = new SourceNode(sqlSource, "SQLite Orders");
SourceNode excelSourceNode = new SourceNode(excelSource, "ExcelDS");
SourceNode objectSourceNode = new SourceNode(objectSource, "ObjectDS");
mainQueryCreatedByApi.Root = sqlSourceNode;
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "SalesPerson", Node = objectSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "Weight", Node = objectSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "CategoryName", Node = excelSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "ProductName", Node = excelSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "OrderDate", Node = sqlSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "ShipCity", Node = sqlSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "ShipCountry", Node = sqlSourceNode });
mainQueryCreatedByApi.Expressions.Add(new SelectColumnExpression() { Name = "Extended Price", Node = excelSourceNode });
mainQueryCreatedByApi.SubNodes.Add(new JoinElement(excelSourceNode, JoinType.Inner, "[ExcelDS.OrderID] = [SQLite Orders.OrderID]"));
mainQueryCreatedByApi.SubNodes.Add(new JoinElement(objectSourceNode, JoinType.Inner, "[ObjectDS.SalesPerson] = [ExcelDS.Sales Person]"));
#endregion
#region Use NodedBuilder to join SQL, Excel, and Object Data Sources in a Query
SelectNode mainQueryCreatedByNodeBuilder =
sqlSource.From()
.Select("OrderDate", "ShipCity", "ShipCountry")
.Join(excelSource, "[excel.OrderID] = [sqlite.OrderID]")
.Select("CategoryName", "ProductName", "Extended Price")
.Join(objectSource, "[object.SalesPerson] = [excel.Sales Person]")
.Select("SalesPerson", "Weight")
.Build("FDS-Created-by-NodeBulder");
#endregion
federationDS.Queries.Add(mainQueryCreatedByApi);
federationDS.Queries.Add(mainQueryCreatedByNodeBuilder);
federationDS.CalculatedFields.Add("FDS-Created-by-NodeBulder", "[Weight] * [Extended Price] / 100", "Score");
federationDS.Fill(new DevExpress.Data.IParameter[0]);
return federationDS;
}
// ...
}
}
Create Transformation Query Type
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.DataFederation;
using DevExpress.XtraEditors;
// ...
namespace DataFederationExample {
public partial class Form1 : XtraForm {
// ...
private static DashboardFederationDataSource CreateFederatedDataSourceTransform(DashboardJsonDataSource jsonDataSource) {
DashboardFederationDataSource federationDS = new DashboardFederationDataSource("Federated Data Source (Transformation)");
Source jsonSource = new Source("json", jsonDataSource, "");
SourceNode sourceNode = new SourceNode(jsonSource);
TransformationNode defaultNode = new TransformationNode(sourceNode) {
Alias = "Default",
Rules = { new TransformationRule { ColumnName = "Products", Unfold = false, Flatten = false } }
};
TransformationNode flattenNode = new TransformationNode(sourceNode) {
Alias = "Flatten",
Rules = { new TransformationRule { ColumnName = "Products", Alias = "Product", Unfold = true, Flatten = true } }
};
TransformationNode unfoldNode = new TransformationNode(sourceNode) {
Alias = "Unfold",
Rules = { new TransformationRule { ColumnName = "Products", Alias = "Product", Unfold = true, Flatten = false } }
};
federationDS.Queries.Add(defaultNode);
federationDS.Queries.Add(flattenNode);
federationDS.Queries.Add(unfoldNode);
return federationDS;
}
// ...
}
}
Create Union and UnionAll Query Types
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.DataFederation;
using DevExpress.XtraEditors;
// ...
namespace DataFederationExample {
public partial class Form1 : XtraForm {
// ...
private static DashboardFederationDataSource CreateFederatedDataSourceUnion(DashboardSqlDataSource sqliteDataSource, DashboardExcelDataSource exceldataSource) {
DashboardFederationDataSource federationDS = new DashboardFederationDataSource("Federated Data Source (UNION)");
Source sqlSource = new Source("sqlite", sqliteDataSource, "SQLite Orders");
Source excelSource = new Source("excel", exceldataSource);
UnionNode queryUnionAll = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite")
.UnionAll(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel"))
.Build("OrdersUnionAll");
UnionNode queryUnion = sqlSource.From().Select("OrderID", "OrderDate").Build("OrdersSqlite")
.Union(excelSource.From().Select("OrderID", "OrderDate").Build("OrdersExcel"))
.Build("OrdersUnion");
federationDS.Queries.Add(queryUnionAll);
federationDS.Queries.Add(queryUnion);
federationDS.Fill(new DevExpress.Data.IParameter[0]);
return federationDS;
}
// ...
}
}