Skip to main content

UnionNodeBuilder Class

Provides a Fluent interface method to build a union query.

Namespace: DevExpress.DataAccess.DataFederation

Assembly: DevExpress.DataAccess.v24.2.dll

Declaration

public class UnionNodeBuilder

Remarks

Use the Union(QueryNode, QueryNode) method to access the UnionNodeBuilder‘s object and build a query with a Fluent API.

Example

The following code snippet demonstrates how to use UnionType to create a federated data source from two Excel files. The UnionNodeBuilder‘s Fluent API is used to construct a federated query.

The QueryBuildingExtensions.Union(QueryNode, QueryNode, UnionType) method combines rows from two queries into a single data set and removes duplicate rows.

The result is a new “UnionTable” query that combines the two queries.

using DevExpress.DataAccess.DataFederation;
using DevExpress.DataAccess.Excel;
using System.Linq;

//...

static ExcelDataSource CreateExcelDataSource(string fileName, string worksheetName) {
  var excelDataSource = new ExcelDataSource {
      FileName = fileName,
      SourceOptions = new ExcelSourceOptions {
          SkipEmptyRows = true,
          SkipHiddenColumns = true,
          SkipHiddenRows = true,
          ImportSettings = new ExcelWorksheetSettings { WorksheetName = worksheetName }
      }
  };
    return excelDataSource;
}

public static FederationDataSource CreateFederationDataSource() {
    Source salesPerson1 = new Source("SalesPerson", CreateExcelDataSource("../../../SalesPerson.xlsx", "Data"));
    Source salesPerson2 = new Source("SalesPerson2", CreateExcelDataSource("../../../SalesPerson.xlsx", "Data2"));
    var query =
        salesPerson1.From().Select("CategoryName", "Country", "Sales Person", "OrderDate", "OrderID", "Discount", "Extended Price").Build()
        .Union(
            salesPerson2.From().Select("CategoryName", "Country", "Sales Person", "OrderDate", "OrderID", "Discount", "Extended Price").Build(),
            UnionType.Union
        )
        .Build("UnionTable");
    FederationDataSource federation = new FederationDataSource();
    federation.Queries.Add(query);
    federation.Fill();
    return federation;
}

Inheritance

Object
UnionNodeBuilder
See Also