FederationDataSource Class

A federated data source that integrates different data sources and provides uniform data access with a federated query.

Namespace: DevExpress.DataAccess.DataFederation

Assembly: DevExpress.DataAccess.v20.1.dll

Declaration

[ToolboxSvgImage("DevExpress.DataAccess.Images.FederationDataSource.svg,DevExpress.DataAccess.v20.1, Version=20.1.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672")]
[XRDesigner("DevExpress.DataAccess.UI.Design.XRFederationDataSourceDesigner,DevExpress.DataAccess.v20.1.UI, Version=20.1.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672", typeof(IDesigner))]
public class FederationDataSource :
    FederationDataSourceBase,
    IListSource,
    IFederationListAdapter,
    IListAdapterAsync,
    IListAdapter,
    ISupportInitialize,
    IXtraSerializable,
    IXtraSupportDeserializeCollectionItem
<ToolboxSvgImage("DevExpress.DataAccess.Images.FederationDataSource.svg,DevExpress.DataAccess.v20.1, Version=20.1.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672")>
<XRDesigner("DevExpress.DataAccess.UI.Design.XRFederationDataSourceDesigner,DevExpress.DataAccess.v20.1.UI, Version=20.1.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672", GetType(IDesigner))>
Public Class FederationDataSource
    Inherits FederationDataSourceBase
    Implements IListSource,
               IFederationListAdapter,
               IListAdapterAsync,
               IListAdapter,
               ISupportInitialize,
               IXtraSerializable,
               IXtraSupportDeserializeCollectionItem

Remarks

The FederationDataSource class is a federated data source that integrates different data sources and provides uniform data access with a federated query.

Federated Data Source supports the following data source types:

You can create the federated data source at design time or runtime.

Design Time

Use the Data Source Wizard in Reporting and Dashboards products to create a federated data source and connect to it.

The wizard allows you to create a federated query based on data from other data sources.

Data Source Wizard - Query Builder

The wizard automatically assigns the name to a federated data source and federated query. The federated data source name is "Federation Data Source N" where N is a serial number. The federated query name is the same as the name of the first data source included in the query.

Run Time

Use a default constructor to create a FederationDataSource class instance.

The main part of the Federated Data Source is the FederationDataSourceBase.Queries collection that contains federated queries.

There are two methods to create a federated query:

Fluent Interface

This method uses the SelectNodeBuilder object that provides a fluent interface to build a query tree. Fluent interface allows you to create queries in a few lines of code.

The entry point is the Source.From method. It returns the SelectNodeBuilder instance.

The final point is the SelectNodeBuilder.Build method that returns the query object.

Follow the steps below to build a federated query:

NOTE

The complete sample project How to Create a Federated Data Source at Runtime is available in the DevExpress Examples repository.

The following code sample creates a federated data source with two federated queries from SQL and Excel data sources.

using DevExpress.DataAccess.DataFederation;
// ...
  FederationDataSource federation = new FederationDataSource();

  Source sourceProducts = new Source("Products", CreateSqlDataSource(), "Products");
  Source sourceOrderDetail = new Source("OrderDetail", CreateExcelDataSource("SalesPerson.xlsx", "Data"));
  Source sourceHeader = new Source("OrderHeader", CreateExcelDataSource("OrderHeaders.xlsx", "OrderHeader"));


  SelectNode query1 = sourceProducts.From().Select("ProductName", "QuantityPerUnit", "UnitsInStock")
      .Join(sourceOrderDetail, "[Products.ProductName] = [OrderDetail.ProductName]")
      .Select("OrderDate")
      .Build("ProductsOrderDetail");

  SelectNode query2 = sourceHeader.From().Select("OrderID", "Status", "Description")
      .Join(sourceOrderDetail, "[OrderHeader.OrderID] = [OrderDetail.OrderID]")
      .Select("Quantity", "Extended Price")
      .Build("OrderHeaderOrderDetail");

  federation.Queries.AddRange(new[] { query1, query2 });
  federation.Fill();

Data Federation API

This method builds a query tree by instantiating objects and adding them to the collections.

Follow the steps below to build a federated query:

NOTE

The complete sample project How to Create a Federated Data Source at Runtime is available in the DevExpress Examples repository.

The following code sample creates a federated data source with a federated query from SQL and Excel data sources.

using DevExpress.DataAccess.DataFederation;
// ...
  FederationDataSource federation = new FederationDataSource();

  Source sourceProducts = new Source("Products", CreateSqlDataSource(), "Products");
  Source sourceOrderDetail = new Source("OrderDetail", CreateExcelDataSource("SalesPerson.xlsx", "Data"));

  var sourceNodeProducts = new SourceNode(sourceProducts, "Products");
  var sourceNodeOrderDetail = new SourceNode(sourceOrderDetail, "OrderDetail");

  var query = new SelectNode(sourceNodeProducts)
  {
      Alias = "ProductsOrderDetail",
      SubNodes = {
              new JoinElement {
                  Node = sourceNodeOrderDetail,
                  Condition = $"[{sourceNodeProducts.Alias}.ProductName] == [{sourceNodeOrderDetail.Alias}.ProductName]"
              }
          },
      Expressions = {
          new SelectColumnExpression(sourceNodeProducts, "ProductName"),
          new SelectColumnExpression(sourceNodeProducts, "QuantityPerUnit"),
          new SelectColumnExpression(sourceNodeOrderDetail, "OrderID"),
          new SelectColumnExpression(sourceNodeOrderDetail, "OrderDate"),
          new SelectColumnExpression(sourceNodeOrderDetail, "Quantity"),
          new SelectColumnExpression(sourceNodeOrderDetail, "UnitPrice")
          }
  };
  federation.Queries.Add(query);
  federation.Fill();

Inheritance

Object
MarshalByRefObject
Component
DevExpress.DataAccess.DataComponentBase
FederationDataSourceBase
FederationDataSource
See Also