Class InMemoryDataProvider
- Namespace
- combit.Reporting.DataProviders
- Assembly
- combit.ListLabel31.CrossPlatform.dll
Provides an in-memory data provider that wraps existing ITable instances and allows for the addition of relations, thereby offering a more feature-rich and flexible means of accessing data from various sources (e.g. CSV, etc.).
public sealed class InMemoryDataProvider : SQLiteConnectionDataProvider, IDataProvider, ICanHandleUsedIdentifiers, IDisposable, ISupportsLogger, ISerializable
- Inheritance
-
InMemoryDataProvider
- Implements
- Inherited Members
Examples
// Create a CSV data provider for customer data
CsvDataProvider csv = new CsvDataProvider(@"D:\datasources\customer.txt", true, "Customers", ',');
// Create an Excel data provider for order data
XlsDataProvider xls = new XlsDataProvider(@"D:\datasources\Orders.xlsx", true);
// Initialize an in-memory data provider
InMemoryDataProvider inmem = new InMemoryDataProvider();
// Add both datasets to the in-memory provider
inmem.AddTable(csv, "Customers");
inmem.AddTable(xls, "Orders");
// Define a relationship between Customers and Orders based on CustomerID
inmem.AddRelation("Customers", "Orders", "CustomerID", "CustomerID");
// Assign the in-memory data provider to the LL component
LL.DataSource = inmem;
Remarks
This data provider extends SQLiteConnectionDataProvider and is designed to work in scenarios where the data is to be loaded to memory, such as when importing data from CSV files or other non-relational sources. It enables you to define custom relations between tables. This allows you to build a more complete data model on top of disparate data sources.
Methods
AddRelation(string, string, string, string, string)
Defines a relation between two existing tables in this data provider.
public void AddRelation(string relationName, string parentTableName, string childTableName, string parentColumnName, string childColumnName)
Parameters
relationNamestringThe name of the relation to use. If null or empty, the relation will be auto-named using the parent and child table names.
parentTableNamestringThe name of the parent table.
childTableNamestringThe name of the child table.
parentColumnNamestringThe name of the column from the parent table that participates in the relation.
childColumnNamestringThe name of the column from the child table that participates in the relation.
Exceptions
- ListLabelException
Thrown if a relation with the specified (or auto-generated) name has already been defined.
AddTable(IDataProvider, string)
Adds a new table from an existing data provider using the table name as both the source and external name.
public void AddTable(IDataProvider provider, string tableName)
Parameters
providerIDataProviderThe data provider containing the new table to be added.
tableNamestringThe name of the table in the data provider. To use a different external name, use the overload that accepts an alias. This is particularly useful if tables with the same name exist in different data providers.
AddTable(IDataProvider, string, string)
Adds a new table from an existing data provider.
public void AddTable(IDataProvider provider, string tableName, string tableAlias)
Parameters
providerIDataProviderThe data provider containing the new table to be added.
tableNamestringThe name of the table in the data provider.
tableAliasstringAn alias name for the new table. If provided, this alias will be used as the external table name.
Exceptions
- ListLabelException
Thrown if the provider is null, if the table name is null or empty, or if the specified table cannot be found.
AddTable(ITable)
Adds a new table to the in-memory data provider from an object implementing the ITable interface.
public void AddTable(ITable table)
Parameters
Exceptions
- ArgumentNullException
Thrown if the provided table is null.
Init()
Initializes the in-memory data provider by registering tables and relations from the underlying SQLite connection.
protected override void Init()
Remarks
This method will only execute once. It uses an combit.Reporting.DataProviders.InMemoryHelper to add tables to the provider.
Tables or relations that are suppressed (based on custom logic in SuppressAddTableOrRelation) will not be added.
If a table does not contain any data, it is not registered and a warning is logged.