Search Results for

    Show / Hide Table of Contents

    Class QueryableExtensions

    Useful extension methods for use with Entity Framework LINQ queries.

    Inheritance
    object
    QueryableExtensions
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: PnP.Core.QueryModel
    Assembly: PnP.Core.dll
    Syntax
    public static class QueryableExtensions

    Methods

    AsAsyncEnumerable<TSource>(IQueryable<TSource>)

    Returns an IAsyncEnumerable<T> which can be enumerated asynchronously.

    Declaration
    public static IAsyncEnumerable<TSource> AsAsyncEnumerable<TSource>(this IQueryable<TSource> source)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to enumerate.

    Returns
    IAsyncEnumerable<TSource>

    The query results.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    InvalidOperationException

    source is null.

    ArgumentNullException

    source is not a IAsyncEnumerable<T>.

    AsBatchAsync<TSource>(IQueryable<TSource>)

    Adds the query to the current batch

    Declaration
    public static Task<IEnumerableBatchResult<TSource>> AsBatchAsync<TSource>(this IQueryable<TSource> source)
    Parameters
    IQueryable<TSource> source

    Returns
    Task<IEnumerableBatchResult<TSource>>

    Type Parameters
    TSource

    AsBatchAsync<TSource>(IQueryable<TSource>, Batch)

    Adds the query to the specified batch

    Declaration
    public static Task<IEnumerableBatchResult<TSource>> AsBatchAsync<TSource>(this IQueryable<TSource> source, Batch batch)
    Parameters
    IQueryable<TSource> source

    Batch batch

    Returns
    Task<IEnumerableBatchResult<TSource>>

    Type Parameters
    TSource

    AsBatch<TSource>(IQueryable<TSource>)

    Adds the query to the current batch

    Declaration
    public static IEnumerableBatchResult<TSource> AsBatch<TSource>(this IQueryable<TSource> source)
    Parameters
    IQueryable<TSource> source

    Returns
    IEnumerableBatchResult<TSource>

    Type Parameters
    TSource

    AsBatch<TSource>(IQueryable<TSource>, Batch)

    Adds the query to the specified batch

    Declaration
    public static IEnumerableBatchResult<TSource> AsBatch<TSource>(this IQueryable<TSource> source, Batch batch)
    Parameters
    IQueryable<TSource> source

    Batch batch

    Returns
    IEnumerableBatchResult<TSource>

    Type Parameters
    TSource

    AsRequested<TSource>(IDataModelCollection<TSource>)

    Returns an IEnumerable<T> which can be enumerated without executing an actual LINQ query on the target data provider.

    Declaration
    public static IEnumerable<TSource> AsRequested<TSource>(this IDataModelCollection<TSource> source)
    Parameters
    IDataModelCollection<TSource> source

    An IDataModelCollection<TModel> to enumerate.

    Returns
    IEnumerable<TSource>

    The query results.

    Type Parameters
    TSource

    The type of the elements of source.

    Exceptions
    InvalidOperationException

    source is null.

    ArgumentNullException

    source is not a IAsyncEnumerable<T>.

    FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

    Asynchronously returns the first element of a sequence that satisfies a specified condition.

    Declaration
    public static Task<TSource> FirstAsync<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to return the first element of.

    Expression<Func<TSource, bool>> predicate

    A function to test each element for a condition.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains the first element in source that passes the test in predicate.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or predicate is null.

    InvalidOperationException

    No element satisfies the condition in predicate

    -or -

    source contains no elements.

    OperationCanceledException

    If the CancellationToken is canceled.

    FirstAsync<TSource>(IQueryable<TSource>, CancellationToken)

    Asynchronously returns the first element of a sequence.

    Declaration
    public static Task<TSource> FirstAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to return the first element of.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains the first element in source.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source is null.

    InvalidOperationException

    source contains no elements.

    OperationCanceledException

    If the CancellationToken is canceled.

    FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

    Asynchronously returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.

    Declaration
    public static Task<TSource> FirstOrDefaultAsync<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to return the first element of.

    Expression<Func<TSource, bool>> predicate

    A function to test each element for a condition.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains default ( TSource ) if source is empty or if no element passes the test specified by predicate ; otherwise, the first element in source that passes the test specified by predicate.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or predicate is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    FirstOrDefaultAsync<TSource>(IQueryable<TSource>, CancellationToken)

    Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.

    Declaration
    public static Task<TSource> FirstOrDefaultAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to return the first element of.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains default ( TSource ) if source is empty; otherwise, the first element in source.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ForEachAsync<T>(IQueryable<T>, Action<T>, CancellationToken)

    Asynchronously enumerates the query results and performs the specified action on each element.

    Declaration
    public static Task ForEachAsync<T>(this IQueryable<T> source, Action<T> action, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<T> source

    An IQueryable<T> to enumerate.

    Action<T> action

    The action to perform on each element.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task

    A task that represents the asynchronous operation.

    Type Parameters
    T

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or action is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    QueryProperties<TResult>(ISupportQuery<TResult>, params Expression<Func<TResult, object>>[])

    Extension method to declare a field/metadata property to load while executing the REST query

    Declaration
    public static ISupportQuery<TResult> QueryProperties<TResult>(this ISupportQuery<TResult> source, params Expression<Func<TResult, object>>[] selectors)
    Parameters
    ISupportQuery<TResult> source

    The collection of items to load the field/metadata from

    Expression<Func<TResult, object>>[] selectors

    A selector for a field/metadata

    Returns
    ISupportQuery<TResult>

    The resulting collection

    Type Parameters
    TResult

    The type of the target entity

    QueryProperties<TResult>(IQueryable<TResult>, params Expression<Func<TResult, object>>[])

    Extension method to declare the fields/metadata properties to load while executing the REST query

    Declaration
    public static IQueryable<TResult> QueryProperties<TResult>(this IQueryable<TResult> source, params Expression<Func<TResult, object>>[] selectors)
    Parameters
    IQueryable<TResult> source

    The collection of items to load fields/metadata from

    Expression<Func<TResult, object>>[] selectors

    An array of selectors for the fields/metadata

    Returns
    IQueryable<TResult>

    The resulting collection

    Type Parameters
    TResult

    The type of the target entity

    ToArrayAsync<TSource>(IQueryable<TSource>, CancellationToken)

    Asynchronously creates an array from an IQueryable<T> by enumerating it asynchronously.

    Declaration
    public static Task<TSource[]> ToArrayAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create an array from.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<TSource[]>

    A task that represents the asynchronous operation. The task result contains an array that contains elements from the input sequence.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ToDictionaryAsync<TSource, TKey>(IQueryable<TSource>, Func<TSource, TKey>, IEqualityComparer<TKey>, CancellationToken)

    Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function and a comparer.

    Declaration
    public static Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default) where TKey : notnull
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create a Dictionary<TKey, TValue> from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    IEqualityComparer<TKey> comparer

    An IEqualityComparer<T> to compare keys.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<Dictionary<TKey, TSource>>

    A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains selected keys and values.

    Type Parameters
    TSource

    The type of the elements of source.

    TKey

    The type of the key returned by keySelector.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or keySelector is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ToDictionaryAsync<TSource, TKey>(IQueryable<TSource>, Func<TSource, TKey>, CancellationToken)

    Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function.

    Declaration
    public static Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) where TKey : notnull
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create a Dictionary<TKey, TValue> from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<Dictionary<TKey, TSource>>

    A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains selected keys and values.

    Type Parameters
    TSource

    The type of the elements of source.

    TKey

    The type of the key returned by keySelector.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or keySelector is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>, CancellationToken)

    Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.

    Declaration
    public static Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default) where TKey : notnull
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create a Dictionary<TKey, TValue> from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    Func<TSource, TElement> elementSelector

    A transform function to produce a result element value from each element.

    IEqualityComparer<TKey> comparer

    An IEqualityComparer<T> to compare keys.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<Dictionary<TKey, TElement>>

    A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains values of type TElement selected from the input sequence.

    Type Parameters
    TSource

    The type of the elements of source.

    TKey

    The type of the key returned by keySelector.

    TElement

    The type of the value returned by elementSelector.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or keySelector or elementSelector is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, CancellationToken)

    Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector and an element selector function.

    Declaration
    public static Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default) where TKey : notnull
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create a Dictionary<TKey, TValue> from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    Func<TSource, TElement> elementSelector

    A transform function to produce a result element value from each element.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<Dictionary<TKey, TElement>>

    A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains values of type TElement selected from the input sequence.

    Type Parameters
    TSource

    The type of the elements of source.

    TKey

    The type of the key returned by keySelector.

    TElement

    The type of the value returned by elementSelector.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source or keySelector or elementSelector is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    ToListAsync<TSource>(IQueryable<TSource>, CancellationToken)

    Asynchronously creates a List<T> from an IQueryable<T> by enumerating it asynchronously.

    Declaration
    public static Task<List<TSource>> ToListAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
    Parameters
    IQueryable<TSource> source

    An IQueryable<T> to create a list from.

    CancellationToken cancellationToken

    A CancellationToken to observe while waiting for the task to complete.

    Returns
    Task<List<TSource>>

    A task that represents the asynchronous operation. The task result contains a List<T> that contains elements from the input sequence.

    Type Parameters
    TSource

    The type of the elements of source.

    Remarks

    Multiple active operations on the same context instance are not supported. Use await to ensure that any asynchronous operations have completed before calling another method on this context.

    Exceptions
    ArgumentNullException

    source is null.

    OperationCanceledException

    If the CancellationToken is canceled.

    Back to top PnP Core SDK
    Generated by DocFX with Material UI
    spacer