Class ODataDataProvider
- Namespace
- combit.Reporting.DataProviders
- Assembly
- combit.ListLabel31.CrossPlatform.dll
Provides a data provider implementation for OData (Open Data Protocol) endpoints.
public sealed class ODataDataProvider : IDataProvider, ICanHandleUsedIdentifiers, IDisposable, ISupportsLogger
- Inheritance
-
ODataDataProvider
- Implements
- Inherited Members
Examples
The following example demonstrates how to use the ODataDataProvider to export a report to PDF:
// Example 1: Connect to a public OData service
ODataDataProvider provider = new ODataDataProvider(
"https://services.odata.org/V4/Northwind/Northwind.svc/",
retrieveRealValuesForDesigner: true);
// Optional: Configure connection settings
provider.ConnectionTimeout = 60;
provider.MaximumEmbeddedFieldDepth = 3;
// 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: Connect with authentication
NetworkCredential credentials = new NetworkCredential("username", "password", "domain");
ODataDataProvider authProvider = new ODataDataProvider(
"https://api.example.com/odata/",
retrieveRealValuesForDesigner: false,
networkCredential: credentials);
// Example 3: Use custom HTTP headers (e.g., API key)
ODataDataProvider apiKeyProvider = new ODataDataProvider(
"https://api.example.com/odata/",
retrieveRealValuesForDesigner: true);
apiKeyProvider.Headers.Add("X-API-Key", "your_api_key_here");
apiKeyProvider.Headers.Add("Accept", "application/json");
// Example 4: Use local metadata file for faster initialization
ODataDataProvider cachedProvider = new ODataDataProvider(
"https://api.example.com/odata/",
retrieveRealValuesForDesigner: true,
networkCredential: null,
localMetadataFilePath: @"C:\Cache\metadata.xml");
// Example 5: Add custom parameters to queries
ODataDataProvider paramProvider = new ODataDataProvider(
"https://api.example.com/odata/",
retrieveRealValuesForDesigner: true);
// Add parameter for all tables
paramProvider.AddAdditionalParameter("$filter=Status eq 'Active'");
// Add parameter for specific table
paramProvider.AddAdditionalParameter("$top=100", "Customers");
// Example 6: Handle DefineTable event to exclude specific tables
ODataDataProvider eventProvider = new ODataDataProvider(
"https://services.odata.org/V4/Northwind/Northwind.svc/",
retrieveRealValuesForDesigner: true);
eventProvider.DefineTable += (sender, args) =>
{
// Exclude system or unwanted tables
if (args.TableName.StartsWith("System"))
{
args.Suppress = true;
}
};
Remarks
The ODataDataProvider class implements IDataProvider, ICanHandleUsedIdentifiers, IDisposable, ISupportsLogger, and combit.Reporting.DataProviders.ISupportsParameters to provide comprehensive OData service connectivity. OData is a REST-based protocol for querying and updating data, widely used for exposing and consuming data over the web. This provider automatically introspects the OData service metadata ($metadata) to discover entity sets, entity types, complex types, enumerations, and navigation properties, creating a complete table and relationship model. It supports OData v3 and v4, handles authentication through network credentials or custom HTTP headers, and provides intelligent query optimization by requesting only used columns ($select) and expanding related entities ($expand). The provider supports filtering, sorting, and paging through OData query options. It includes caching mechanisms for metadata and data to improve performance. Legacy mode is available for backward compatibility with existing reports. The MaximumEmbeddedFieldDepth property controls how deeply nested 1:1 relationships are flattened into the parent table. Custom parameters can be added to queries for specific tables or globally.
Constructors
ODataDataProvider(string, bool)
Initializes a new instance of the ODataDataProvider class with the specified URL and a flag indicating whether to retrieve real values for the designer.
public ODataDataProvider(string url, bool retrieveRealValuesForDesigner)
Parameters
urlstringThe URL of the OData service.
retrieveRealValuesForDesignerboolIf set to
true, real values will be retrieved for the designer.
ODataDataProvider(string, bool, ICredentials)
Initializes a new instance of the ODataDataProvider class with the specified URL, a flag indicating whether to retrieve real values for the designer, and network credentials.
public ODataDataProvider(string url, bool retrieveRealValuesForDesigner, ICredentials networkCredential)
Parameters
urlstringThe URL of the OData service.
retrieveRealValuesForDesignerboolIf set to
true, real values will be retrieved for the designer.networkCredentialICredentialsThe network credentials used for authentication.
ODataDataProvider(string, bool, ICredentials, string)
Initializes a new instance of the ODataDataProvider class with the specified URL, a flag indicating whether to retrieve real values for the designer, network credentials, and a local metadata file path.
public ODataDataProvider(string url, bool retrieveRealValuesForDesigner, ICredentials networkCredential, string localMetadataFilePath)
Parameters
urlstringThe URL of the OData service.
retrieveRealValuesForDesignerboolIf set to
true, real values will be retrieved for the designer.networkCredentialICredentialsThe network credentials used for authentication.
localMetadataFilePathstringThe file path to a local metadata file.
Properties
ConnectionTimeout
Gets or sets the connection timeout (in seconds) for OData requests.
public int ConnectionTimeout { get; set; }
Property Value
Headers
Gets the collection of HTTP headers that should be used for the request.
public HttpRequestHeaders Headers { get; }
Property Value
LegacyMode
Gets or sets a value indicating whether legacy mode is enabled. This property exists for backward compatibility with existing reports.
[Obsolete("Just for backward compatibility with existing reports.")]
public bool LegacyMode { get; set; }
Property Value
MaximumEmbeddedFieldDepth
Gets or sets the maximum depth for embedded fields.
public int MaximumEmbeddedFieldDepth { get; set; }
Property Value
NetworkCredential
Gets the network credentials used for authentication.
public ICredentials NetworkCredential { get; }
Property Value
Url
Gets the OData service URL.
public string Url { get; }
Property Value
Methods
AddAdditionalParameter(string, string?)
Adds an additional url parameter to the OData query for the given tableName.
If tableName is null the parameter will be added to all tables.
public void AddAdditionalParameter(string parameter, string? tableName = null)
Parameters
parameterstringThe parameter that should be added to the url for the given
tableNamee.g.Company={{Company=combit|choices=combit,Contoso}}tableNamestringThe name of the table where the
parametershould be added in the request. If null the parameter will be added to all tables.
Examples
provider.AddAdditionalParameter("Company={{Company=combit|choices=combit,Contoso}}"); //All tables provider.AddAdditionalParameter("CustomerPrefix={{CustomerPrefix=AB|choices=AB,CD}}", "Customers"); //Specific table (will also have parameters specified for all tables)
Exceptions
- InvalidOperationException
Thrown if the metadata is already loaded (Parameters can only be defined before the initialization took place).
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
~ODataDataProvider()
protected ~ODataDataProvider()
Events
DefineTable
Occurs before adding a new table or its relations. This event allows the caller to suppress the addition of the table.
public event EventHandler<DefineTableEventArgs> DefineTable