Table of Contents

Class ODataContext

Namespace
Utils.OData
Assembly
Utils.OData.dll

Provides a base class for generated OData contexts. The context is initialized from an EDMX definition provided as a stream or a path.

public abstract class ODataContext
Inheritance
ODataContext
Inherited Members
Extension Methods

Remarks

The synchronous constructors are retained for backward compatibility with generated code. They perform blocking I/O and, for remote URLs, block a thread on a network call (item 14 / item 29). New code should prefer the asynchronous CreateAsync and LoadMetadataAsync(string, ODataMetadataOptions?, CancellationToken) factory methods, which accept a caller-supplied HttpClient, honour a CancellationToken, and apply a consistent bounded size policy to every metadata source (items 15, 16, 33, 34).

Constructors

ODataContext(Stream)

Initializes a new instance of the ODataContext class from the specified EDMX stream.

protected ODataContext(Stream edmxStream)

Parameters

edmxStream Stream

Stream containing the EDMX metadata to load.

Exceptions

ArgumentNullException

Thrown when edmxStream is null.

InvalidOperationException

Thrown when the EDMX metadata cannot be parsed.

ODataContext(string)

Initializes a new instance of the ODataContext class from the specified file or URL.

protected ODataContext(string edmxPathOrUrl)

Parameters

edmxPathOrUrl string

Path or HTTP/HTTPS URL pointing to an EDMX file.

Exceptions

ArgumentException

Thrown when edmxPathOrUrl is null or empty.

InvalidOperationException

Thrown when the EDMX metadata cannot be read or parsed.

ODataContext(Edmx)

Initializes a new instance of the ODataContext class from already-parsed metadata. This constructor performs no I/O and is used by the asynchronous factory methods.

protected ODataContext(Edmx metadata)

Parameters

metadata Edmx

The parsed EDMX metadata.

Exceptions

ArgumentNullException

Thrown when metadata is null.

Properties

Metadata

Gets the EDMX metadata loaded for the current context.

public Edmx Metadata { get; }

Property Value

Edmx

Methods

CreateAsync<TContext>(Stream, Func<Edmx, TContext>, ODataMetadataOptions?, CancellationToken)

Asynchronously creates a context instance from a caller-provided EDMX stream, delegating parsing to LoadMetadataFromStreamAsync(Stream, ODataMetadataOptions?, CancellationToken) and then constructing TContext through the supplied factory.

public static Task<TContext> CreateAsync<TContext>(Stream edmxStream, Func<Edmx, TContext> factory, ODataMetadataOptions? options = null, CancellationToken cancellationToken = default) where TContext : ODataContext

Parameters

edmxStream Stream

Stream containing the EDMX content.

factory Func<Edmx, TContext>

Factory that builds the context from the parsed metadata.

options ODataMetadataOptions

Optional loading options. When null, Default is used.

cancellationToken CancellationToken

Token used to cancel the load operation.

Returns

Task<TContext>

A task producing the constructed context.

Type Parameters

TContext

Concrete context type to create.

Exceptions

ArgumentNullException

Thrown when edmxStream or factory is null.

CreateAsync<TContext>(string, Func<Edmx, TContext>, ODataMetadataOptions?, CancellationToken)

Asynchronously creates a context instance from an EDMX file path or HTTP/HTTPS URL, delegating loading to LoadMetadataAsync(string, ODataMetadataOptions?, CancellationToken) and then constructing TContext through the supplied factory.

public static Task<TContext> CreateAsync<TContext>(string edmxPathOrUrl, Func<Edmx, TContext> factory, ODataMetadataOptions? options = null, CancellationToken cancellationToken = default) where TContext : ODataContext

Parameters

edmxPathOrUrl string

Path or HTTP/HTTPS URL pointing to an EDMX resource.

factory Func<Edmx, TContext>

Factory that builds the context from the parsed metadata.

options ODataMetadataOptions

Optional loading options. When null, Default is used.

cancellationToken CancellationToken

Token used to cancel the load operation.

Returns

Task<TContext>

A task producing the constructed context.

Type Parameters

TContext

Concrete context type to create.

Exceptions

ArgumentException

Thrown when edmxPathOrUrl is null or whitespace.

ArgumentNullException

Thrown when factory is null.

LoadMetadataAsync(string, ODataMetadataOptions?, CancellationToken)

Loads and parses EDMX metadata from the specified file path or HTTP/HTTPS URL without blocking the calling thread, using a caller-supplied transport and a bounded size policy.

public static Task<Edmx> LoadMetadataAsync(string edmxPathOrUrl, ODataMetadataOptions? options = null, CancellationToken cancellationToken = default)

Parameters

edmxPathOrUrl string

Path or HTTP/HTTPS URL pointing to an EDMX resource.

options ODataMetadataOptions

Optional loading options controlling the maximum metadata size, the HttpClient to reuse, the download timeout, and the cross-host redirect policy. When null, Default is used.

cancellationToken CancellationToken

Token used to cancel the load operation.

Returns

Task<Edmx>

A task producing the parsed Edmx metadata.

Exceptions

ArgumentException

Thrown when edmxPathOrUrl is null or whitespace.

InvalidOperationException

Thrown when the metadata cannot be read or parsed.

LoadMetadataFromStreamAsync(Stream, ODataMetadataOptions?, CancellationToken)

Loads and parses EDMX metadata from a caller-provided stream without blocking the calling thread, enforcing the configured maximum size (item 15 / item 33).

public static Task<Edmx> LoadMetadataFromStreamAsync(Stream edmxStream, ODataMetadataOptions? options = null, CancellationToken cancellationToken = default)

Parameters

edmxStream Stream

Stream containing the EDMX content.

options ODataMetadataOptions

Optional loading options controlling the maximum metadata size. When null, Default is used.

cancellationToken CancellationToken

Token used to cancel the load operation.

Returns

Task<Edmx>

A task producing the parsed Edmx metadata.

Remarks

For seekable streams the EDMX document is read starting at the stream's current Position. The size limit is checked against the number of bytes remaining from that position, not the total stream length. The position is not reset before reading.

Exceptions

ArgumentNullException

Thrown when edmxStream is null.

InvalidOperationException

Thrown when the metadata cannot be parsed or exceeds the size limit.

Query<TEntity>(string)

Creates a queryable sequence targeting the specified entity set.

protected ODataQueryable<TEntity> Query<TEntity>(string entitySetName)

Parameters

entitySetName string

Name of the entity set to query.

Returns

ODataQueryable<TEntity>

An ODataQueryable<TEntity> representing the entity set.

Type Parameters

TEntity

Type of the entity returned by the query.

Exceptions

ArgumentException

Thrown when entitySetName is null or whitespace.

Table(string)

Creates a queryable sequence for an entity set when no CLR type exists for the table.

public ODataQueryable<ODataUntypedRow> Table(string entitySetName)

Parameters

entitySetName string

Name of the entity set to query.

Returns

ODataQueryable<ODataUntypedRow>

An untyped ODataQueryable<TEntity> that exposes ODataUntypedRow instances.

Exceptions

ArgumentException

Thrown when entitySetName is null or whitespace.