A .NET library for generating dynamic reports and exports from EF Core entities, with support for filtering, sorting, pagination, and multiple export formats (CSV, Excel, JSON).
- 📊 Dynamic Reporting: Generate reports from any EF Core entity
- 🔍 Filtering: Support for multiple filter operators (Eq, Gt, Gte, Lt, Lte, Contains, StartsWith, EndsWith)
- 📈 Sorting: Sort by any column in ascending or descending order
- 📄 Pagination: Built-in pagination support with customizable page sizes
- 📁 Export Formats: CSV, Excel (.xlsx), and JSON
- ⚡ Performance: Optimized EF Core queries with AsNoTracking
Add the ReportEngine library to your project:
dotnet add reference path/to/ReportEngine.csprojusing ReportEngine;
// In Program.cs
builder.Services.AddReportEngine<YourDbContext>();using ReportEngine.Models;
using ReportEngine.Services;
public class ProductsController
{
private readonly IReportService _reportService;
public ProductsController(IReportService reportService)
{
_reportService = reportService;
}
public async Task<IActionResult> ExportProducts()
{
var request = new ReportRequest
{
Columns = ["Name", "Price", "Category", "Status"],
Filters = [new Filter("Price", FilterOperator.Gte, 100)],
Sorts = [new Sort("Name", SortDirection.Asc)],
Pagination = new Pagination(1, 100),
Format = ExportFormat.Excel
};
var bytes = await _reportService.GenerateReportAsync<Product>(request);
var contentType = _reportService.GetContentType(request.Format);
var fileName = $"products{_reportService.GetFileExtension(request.Format)}";
return File(bytes, contentType, fileName);
}
}var request = new ReportRequest
{
Filters = [new Filter("Category", FilterOperator.Eq, "Electronics")],
Pagination = new Pagination(1, 10)
};
var result = await _reportService.QueryAsync<Product>(request);
// result.Data - List of products
// result.TotalCount - Total count before pagination
// result.Page - Current page
// result.PageSize - Items per page
// result.TotalPages - Total number of pages| Property | Type | Description |
|---|---|---|
| Columns | string[]? | Columns to include in the export. If null, all columns are included. |
| Filters | Filter[]? | Filters to apply to the query. |
| Sorts | Sort[]? | Sort specifications. |
| Pagination | Pagination? | Pagination settings. |
| Format | ExportFormat | Export format (Csv, Excel, Json). |
| Operator | Description |
|---|---|
| Eq | Equal to |
| Neq | Not equal to |
| Gt | Greater than |
| Gte | Greater than or equal |
| Lt | Less than |
| Lte | Less than or equal |
| Contains | String contains |
| StartsWith | String starts with |
| EndsWith | String ends with |
The samples/ReportEngine.Sample directory contains a Blazor application demonstrating:
- Product listing with filtering, sorting, and pagination
- Export to CSV and Excel formats
- Interactive UI with Bootstrap styling
cd samples/ReportEngine.Sample
dotnet runNavigate to https://localhost:5001/products to see the demo.
MIT