Skip to main content

SelectNode Class

A node that provides data with a SELECT query.

Namespace: DevExpress.DataAccess.DataFederation

Assembly: DevExpress.DataAccess.v24.1.dll

NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap

Declaration

public class SelectNode :
    QueryNode

The following members return SelectNode objects:

Remarks

The SelectNode objects are contained in the QueryNodeCollection accessible with the FederationDataSourceBase.Queries property.

You can create a Join federated query in the following ways:

Fluent Interface

This method uses the SelectNodeBuilder object that provides a fluent interface to build a query tree. A 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:

  • Create a Source object for each data source integrated in the federated data source.
  • Choose the source that becomes the query root and call its Source.From extension method.
  • Chain SelectNodeBuilder method calls, such as Select and Join, to build a query.
  • Call the SelectNodeBuilder.Build method to finalize the process.
  • Assign the resulting query to the SelectNode instance.
  • Add the SelectNode object to the FederationDataSourceBase.Queries collection.

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

View Example

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:

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

View Example

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();

Example

This code snippet demonstrates how to create a federated data source that uses a filter with a parameter.

Note

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

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

    Source source = new Source("excelSource", CreateExcelDataSource("SalesPerson.xlsx", "Data"));

    var sourceNode = new SourceNode(source, "Orders");

    var query = new SelectNode(sourceNode)
    {
        Alias = "excel",
        Expressions = {
                new SelectColumnExpression(sourceNode, "OrderID"),
                new SelectColumnExpression(sourceNode, "OrderDate"),
                new SelectColumnExpression(sourceNode, "Sales Person"),
                new SelectColumnExpression(sourceNode, "ProductName"),
                new SelectColumnExpression(sourceNode, "Extended Price")
            },
        FilterString = "[Orders.CategoryName] = ?cat",
    };
    federation.Queries.Add(query);
    federation.Fill(new[] { 
        new DevExpress.DataAccess.Sql.QueryParameter("cat", typeof(string), "Seafood") });

Inheritance

Object
QueryNode
SelectNode
See Also