Skip to main content
All docs
V24.1

Bind a Report to a Transformation-Based Data Source (Runtime Sample)

  • 3 minutes to read

This example demonstrates how to create a federated data source that unfolds another data source’s complex objects and flattens them in a simple data set.

Data Source Structure Transformation

View Example: How to Bind a Report to a Transformation-Based Query

Create a JSON Data Source

Create a JsonDataSource object that retrieves data from the Products.json file.

Products.json
[
  {
    "CategoryId": 1,
    "CategoryName": "Beverages",
    "Description": "Soft drinks, coffees, teas, beers, and ales",
    "Products": [
      {
        "ProductId": 1,
        "ProductName": "Chai",
        "SupplierId": 1,
        "CategoryId": 1,
        "QuantityPerUnit": "10 boxes x 20 bags",
        "UnitPrice": 18.0000,
        "UnitsInStock": 39,
        "UnitsOnOrder": 0,
        "ReorderLevel": 10,
        "Discontinued": false,
        "Supplier": null
      },
      {
        "ProductId": 2,
        "ProductName": "Chang",
        "SupplierId": 1,
        "CategoryId": 1,
        "QuantityPerUnit": "24 - 12 oz bottles",
        "UnitPrice": 19.0000,
        "UnitsInStock": 17,
        "UnitsOnOrder": 40,
        "ReorderLevel": 25,
        "Discontinued": false,
        "Supplier": null
      }
    ]
  },
  {
    "CategoryId": 2,
    "CategoryName": "Condiments",
    "Description": "Sweet and savory sauces, relishes, spreads, and seasonings",
    "Products": [
      {
        "ProductId": 3,
        "ProductName": "Aniseed Syrup",
        "SupplierId": 1,
        "CategoryId": 2,
        "QuantityPerUnit": "12 - 550 ml bottles",
        "UnitPrice": 10.0000,
        "UnitsInStock": 13,
        "UnitsOnOrder": 70,
        "ReorderLevel": 25,
        "Discontinued": false,
        "Supplier": null
      },
      {
        "ProductId": 4,
        "ProductName": "Chef Anton's Cajun Seasoning",
        "SupplierId": 2,
        "CategoryId": 2,
        "QuantityPerUnit": "48 - 6 oz jars",
        "UnitPrice": 22.0000,
        "UnitsInStock": 53,
        "UnitsOnOrder": 0,
        "ReorderLevel": 0,
        "Discontinued": false,
        "Supplier": null
      }
    ]
  }
]
using DevExpress.DataAccess.Json;
// ...
// Create a JSON data source.
JsonDataSource jsonDataSource = new JsonDataSource();
Uri fileUri = new Uri("Products.json", UriKind.RelativeOrAbsolute);
jsonDataSource.JsonSource = new UriJsonSource(fileUri);
jsonDataSource.Fill();

The data source includes a nested Products collection.

JSON Data in the Field List

Create a Federation Data Source

Create a FederationDataSource object. Use a TransformationNodeBuilder instance to transform the JSON data source into a flat structure.

using DevExpress.DataAccess.DataFederation;
// ...
// Create a Federation data source.
FederationDataSource federationDataSource = new FederationDataSource();
Source jsonSource = new Source("json", jsonDataSource);
TransformationNode query = jsonSource
    .Transform()
    .TransformColumn("Products")
    .Build("Transformation");
federationDataSource.Queries.Add(query);

The data source exposes the flattened structure.

Federation Data Source

Bind a Report to the Federation Data Source

Create a new report and construct a layout similar to the described layout. Use the report’s DataSource and DataMember properties to bind it to a federated data source.

using System.ComponentModel;
using System.Drawing;
using DevExpress.XtraReports.UI;
// ...
// Create a report and bind it to the Federation data source.
XtraReport1 report = new XtraReport1();
report.DataSource = federationDataSource;
report.DataMember = "Transformation";

View the Result

Initialize the End-User Report Designer or Document Viewer and display the report. Refer to the following topics for instructions on how to do this on different platforms:

The following code sample demonstrates how to display the report in the Windows Forms Document Viewer:

// Display the report in the Document Viewer.
documentViewer1.DocumentSource = report;

See Also