Table of Contents

Class ObjectDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides a data provider implementation that uses reflection to parse collections of business objects into tables and relations.

public sealed class ObjectDataProvider : IDataProvider, ICanHandleUsedIdentifiers, ISupportsLogger
Inheritance
ObjectDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to use the ObjectDataProvider to export a report to PDF:

// Example 1: Report on a simple list of objects
var customers = new List<Customer>
{
    new Customer { Id = 1, Name = "John Doe", Email = "john@example.com" },
    new Customer { Id = 2, Name = "Jane Smith", Email = "jane@example.com" }
};

ObjectDataProvider provider = new ObjectDataProvider(customers);

// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;

// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;

// Export the report to PDF.
listLabel.Export(exportConfiguration);

// Example 2: Report with nested collections (1:n relationship)
var orders = new List<Order>
{
    new Order 
    { 
        OrderId = 1001, 
        OrderDate = DateTime.Now,
        Customer = new Customer { Name = "John Doe" },
        OrderItems = new List<OrderItem>
        {
            new OrderItem { ProductName = "Widget", Quantity = 5, Price = 19.99m },
            new OrderItem { ProductName = "Gadget", Quantity = 2, Price = 49.99m }
        }
    }
};

ObjectDataProvider nestedProvider = new ObjectDataProvider(orders);
// This creates an "Order" table and an "OrderItems" child table with automatic relation

// Example 3: Configure structure flattening and recursion depth
ObjectDataProvider flatProvider = new ObjectDataProvider(customers, maximumRecursionDepth: 5);
flatProvider.FlattenStructure = true; // Nested objects become dotted column names

// Example 4: Control recursion with events
ObjectDataProvider eventProvider = new ObjectDataProvider(orders);

eventProvider.HandleEnumerableProperty += (sender, args) =>
{
    // Cancel recursion for specific paths
    if (args.PropertyPath.Contains("DeepNestedCollection"))
    {
        args.CancelRecursion = true;
    }
};

eventProvider.HandleFlattenedProperty += (sender, args) =>
{
    // Control flattening behavior
    if (args.RecursionDepth > 3)
    {
        args.CancelRecursion = true;
    }
};

// Example 5: Report on Entity Framework entities with deferred loading
using (var context = new MyDbContext())
{
    var products = context.Products.ToList();
    ObjectDataProvider efProvider = new ObjectDataProvider(products);

    efProvider.LoadDeferredContent += (sender, args) =>
    {
        // Load related entities on demand
        if (args.PropertyName == "Category")
        {
            context.Entry(args.Source).Reference(args.PropertyName).Load();
        }
    };

    // Use efProvider for reporting...
}

// Example 6: Enable LINQ sorting
ObjectDataProvider sortProvider = new ObjectDataProvider(customers);
sortProvider.UseLinqForSorting = true; // Better performance than IBindingList sorting

Remarks

The ObjectDataProvider class implements IDataProvider, ICanHandleUsedIdentifiers, and ISupportsLogger to enable flexible connectivity to in-memory business object collections. This provider uses reflection to automatically discover object properties, creating a hierarchical table and relationship model from nested objects, collections, and enumerables. It supports any object implementing IEnumerable, IListSource, or plain business objects with properties. The provider automatically detects relationships through enumerable properties (1:n) and class properties (1:1), creating appropriate parent-child relations. Structure flattening is supported to simplify nested object hierarchies into dotted column names. The MaximumRecursionDepth property controls how deep the provider inspects nested objects. Advanced filtering is supported through LINQ expression trees compiled at runtime for optimal performance. The provider supports sorting through LINQ or IBindingList/IBindingListView interfaces. Events enable custom control over parsing behavior and recursion depth. Dictionary properties are automatically expanded into individual columns. Entity Framework collections and deferred loading are supported through the LoadDeferredContent event. The provider is ideal for reporting on in-memory business objects, POCOs, Entity Framework entities, or any collection of .NET objects.

Constructors

ObjectDataProvider(object)

Initializes a new instance of the ObjectDataProvider class using the specified data source. The default maximum recursion depth is set to 3.

public ObjectDataProvider(object source)

Parameters

source object

The business object or collection of business objects to be parsed as a data source.

ObjectDataProvider(object, int)

Initializes a new instance of the ObjectDataProvider class using the specified data source and maximum recursion depth.

public ObjectDataProvider(object source, int maximumRecursionDepth)

Parameters

source object

The business object or collection of business objects to be parsed as a data source.

maximumRecursionDepth int

The maximum recursion depth for parsing nested properties.

Properties

FlattenStructure

Gets or sets a value indicating whether the structure of the data source should be flattened. When set to true, nested properties are merged into a single table structure if possible.

public bool FlattenStructure { get; set; }

Property Value

bool

MaximumRecursionDepth

Gets or sets the maximum recursion depth when parsing the data source structure. This value determines how deep the provider will inspect nested objects.

public int MaximumRecursionDepth { get; set; }

Property Value

int

ObjectForStructureParsing

Gets or sets an alternative object used for structure parsing. This property can be used to override the default reflection-based parsing behavior.

public object ObjectForStructureParsing { get; set; }

Property Value

object

RootTableName

Gets or sets the name of the root table derived from the data source. This property is determined via reflection based on the type of the source object.

public string RootTableName { get; set; }

Property Value

string

Source

Gets the original data source object that is being parsed into a table structure.

public object Source { get; }

Property Value

object

UseLinqForSorting

Allows to switch between LINQ based sorting (default) and sorting via IBindingListView

public bool UseLinqForSorting { get; set; }

Property Value

bool

Events

HandleEnumerableProperty

Occurs before processing an enumerable property in the object data provider. This event allows subscribers to control or cancel the recursion for enumerable properties.

public event EventHandler<HandleEnumerablePropertyEventArgs> HandleEnumerableProperty

Event Type

EventHandler<HandleEnumerablePropertyEventArgs>

HandleFlattenedProperty

Occurs before processing a flattened property in the object data provider. This event enables subscribers to modify the processing or cancel the recursion for flattened properties.

public event EventHandler<HandleFlattenedPropertyEventArgs> HandleFlattenedProperty

Event Type

EventHandler<HandleFlattenedPropertyEventArgs>

LoadDeferredContent

Occurs when deferred content needs to be loaded. Subscribers to this event should handle the loading of content from the specified source and property.

public event EventHandler<LoadDeferredContentEventArgs> LoadDeferredContent

Event Type

EventHandler<LoadDeferredContentEventArgs>