FastReport .NET provides multiple ways to access and work with data, including databases, DataSet, JSON, and Business Objects (regular C# classes in your application).
This article demonstrates a practical example of creating and using an .frx report template that connects to hierarchical Business Objects (Category → Products).
Â
Â
Business Objects offer several advantages over traditional data sources:
Â
Â
First, install the FastReport.Net.Demo NuGet package (or the licensed FastReport.Net package from our private NuGet server), then create the following model classes:
public class Category { public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public List<Product> Products { get; set; } = new List<Product>(); Â public Category() { } Â public Category(string name, string description) { Name = name; Description = description; } } Â public class Product { public string Name { get; set; } = string.Empty; public decimal UnitPrice { get; set; } Â public Product() { } Â public Product(string name, decimal unitPrice) { Name = name; UnitPrice = unitPrice; } }
Â
Next, implement a simple method to populate the data:
static private void CreateBusinessObject() { FBusinessObject.Clear(); Â Category category = new Category("Beverages", "Soft drinks, coffees, teas, beers"); category.Products.Add(new Product("Chai", 18m)); category.Products.Add(new Product("Chang", 19m)); category.Products.Add(new Product("Ipoh coffee", 46m)); FBusinessObject.Add(category); Â category = new Category("Confections", "Desserts, candies, and sweet breads"); category.Products.Add(new Product("Chocolade", 12.75m)); category.Products.Add(new Product("Scottish Longbreads", 12.5m)); category.Products.Add(new Product("Tarte au sucre", 49.3m)); FBusinessObject.Add(category); Â category = new Category("Seafood", "Seaweed and fish"); category.Products.Add(new Product("Boston Crab Meat", 18.4m)); category.Products.Add(new Product("Red caviar", 15m)); FBusinessObject.Add(category); }
Â
To create a report based on the Categories BusinessObject data source, use the following code:
[STAThread] static void Main(string[] args) { Report report = new Report(); CreateBusinessObject(); report.RegisterData(FBusinessObject, "Categories BusinessObject"); report.Design(); }
Important: Call RegisterData after loading the report (report.Load) and before calling report.Prepare().
After launching the report designer, select the data source by opening "Data → Choose Report Data".
Â
Next, create a simple Master-Detail report, or use one of the sample templates included with the FastReport demo projects.
Once the report is ready, run it in Preview mode to verify the output.
Â
Once the report template has been created, you can display it from a Console application using the following code:
[STAThread] static void Main(string[] args) { Report report = new Report(); report.Load(@"Business Objects.frx"); CreateBusinessObject(); report.RegisterData(FBusinessObject, "Categories BusinessObject"); report.Prepare(); report.Show(); report.Dispose(); }
Â
Â
public partial class Form1 : Form { static private List<Category> FBusinessObject = new List<Category>(); Â public Form1() { InitializeComponent(); CreateBusinessObject(); } Â private void CreateBusinessObject() { FBusinessObject.Clear(); Â Category category = new Category("Beverages", "Soft drinks, coffees, teas, beers"); category.Products.Add(new Product("Chai", 18m)); category.Products.Add(new Product("Chang", 19m)); category.Products.Add(new Product("Ipoh coffee", 46m)); FBusinessObject.Add(category); Â category = new Category("Confections", "Desserts, candies, and sweet breads"); category.Products.Add(new Product("Chocolade", 12.75m)); category.Products.Add(new Product("Scottish Longbreads", 12.5m)); category.Products.Add(new Product("Tarte au sucre", 49.3m)); FBusinessObject.Add(category); Â category = new Category("Seafood", "Seaweed and fish"); category.Products.Add(new Product("Boston Crab Meat", 18.4m)); category.Products.Add(new Product("Red caviar", 15m)); FBusinessObject.Add(category); } Â private void btnCreateNew_Click(object sender, EventArgs e) { // create report instance Report report = new Report(); Â // register the business object report.RegisterData(FBusinessObject, "Categories BusinessObject"); Â // design the report report.Design(); Â // free resources used by report report.Dispose(); } Â private void btnRunExisting_Click(object sender, EventArgs e) { // create report instance Report report = new Report(); Â // load the existing report report.Load(@"..\..\Business Objects.frx"); Â // register the business object report.RegisterData(FBusinessObject, "Categories BusinessObject"); Â // run the report report.Show(); Â // free resources used by report report.Dispose(); } } Â Â public class Category { public string Name { get; set; } = string.Empty; public string Description { get; set; } = string.Empty; public List<Product> Products { get; set; } = new List<Product>(); Â public Category() { } Â public Category(string name, string description) { Name = name; Description = description; } } Â public class Product { public string Name { get; set; } = string.Empty; public decimal UnitPrice { get; set; } Â public Product() { } Â public Product(string name, decimal unitPrice) { Name = name; UnitPrice = unitPrice; } }
Â
Â
Business Objects are one of the most modern and convenient ways to work with data in FastReport .NET. They allow you to integrate report generation into your application's architecture in a clean and maintainable way, without introducing unnecessary complexity into your codebase.
This approach is especially well-suited for medium-sized and large projects, where clear separation of concerns, maintainability, and rapid report development are essential.
By using Business Objects, you gain maximum flexibility and full control over how data is supplied to your reports, while keeping your reporting layer closely aligned with your application's domain model.