Search Results for

    Show / Hide Table of Contents

    Class QueryableExtensions

    Useful extension methods for use with Entity Framework LINQ queries.

    Inheritance
    System.Object
    QueryableExtensions
    Namespace: PnP.Core.QueryModel
    Assembly: PnP.Core.dll
    Syntax
    public static class QueryableExtensions : object

    Methods

    AsAsyncEnumerable<TSource>(IQueryable<TSource>)

    Returns an which can be enumerated asynchronously.

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

    An 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.

    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

    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

    AsRequested<TSource>(IDataModelCollection<TSource>)

    Returns an 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.

    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 = null)
    Parameters
    IQueryable<TSource> source

    An to return the first element of.

    CancellationToken cancellationToken

    A 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.

    FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, Boolean>>, 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 = null)
    Parameters
    IQueryable<TSource> source

    An to return the first element of.

    Expression<Func<TSource, System.Boolean>> predicate

    A function to test each element for a condition.

    CancellationToken cancellationToken

    A 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.

    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 = null)
    Parameters
    IQueryable<TSource> source

    An to return the first element of.

    CancellationToken cancellationToken

    A to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains langword_csharp_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.

    FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, Boolean>>, 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 = null)
    Parameters
    IQueryable<TSource> source

    An to return the first element of.

    Expression<Func<TSource, System.Boolean>> predicate

    A function to test each element for a condition.

    CancellationToken cancellationToken

    A to observe while waiting for the task to complete.

    Returns
    Task<TSource>

    A task that represents the asynchronous operation. The task result contains langword_csharp_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.

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

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

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

    An to enumerate.

    Action<T> action

    The action to perform on each element.

    CancellationToken cancellationToken

    A 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.

    QueryProperties<TResult>(IQueryable<TResult>, 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, System.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

    QueryProperties<TResult>(ISupportQuery<TResult>, 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, System.Object>>[] selectors

    A selector for a field/metadata

    Returns
    ISupportQuery<TResult>

    The resulting collection

    Type Parameters
    TResult

    The type of the target entity

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

    Asynchronously creates an array from an by enumerating it asynchronously.

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

    An to create an array from.

    CancellationToken cancellationToken

    A 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.

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

    Creates a from an 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 = null)
    Parameters
    IQueryable<TSource> source

    An to create a from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    CancellationToken cancellationToken

    A 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 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.

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

    Creates a from an 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 = null)
    Parameters
    IQueryable<TSource> source

    An to create a from.

    Func<TSource, TKey> keySelector

    A function to extract a key from each element.

    IEqualityComparer<TKey> comparer

    An to compare keys.

    CancellationToken cancellationToken

    A 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 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.

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

    Creates a from an 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 = null)
    Parameters
    IQueryable<TSource> source

    An to create a 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 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 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.

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

    Creates a from an by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.

    Declaration
    public static async 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 = null)
    Parameters
    IQueryable<TSource> source

    An to create a 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 to compare keys.

    CancellationToken cancellationToken

    A 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 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.

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

    Asynchronously creates a from an by enumerating it asynchronously.

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

    An to create a list from.

    CancellationToken cancellationToken

    A 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 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.

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