Table of Contents

Class NeosQueryableExtensions

Namespace
GroupeIsa.Neos.Shared.Linq
Assembly
GroupeIsa.Neos.Shared.dll

Extensions methods to IQueryable.

public static class NeosQueryableExtensions
Inheritance
NeosQueryableExtensions
Inherited Members

Methods

AddAsyncHandler<THandler>()

Adds a handler for asynchronous execution.

public static void AddAsyncHandler<THandler>() where THandler : IAsyncQueryHandler

Type Parameters

THandler

The type of manager to add.

AddExecutableHandler<THandler>()

Adds an handler for executable queries.

public static void AddExecutableHandler<THandler>() where THandler : IExecutableQueryHandler

Type Parameters

THandler

The handler type.

AddIncludableHandler<THandler>()

Adds a handler for requests with inclusion.

public static void AddIncludableHandler<THandler>() where THandler : IIncludableQueryHandler

Type Parameters

THandler

The type of manager to add.

AddSplittableHandler<THandler>()

Adds an handler for splittable queries.

public static void AddSplittableHandler<THandler>() where THandler : ISplittableQueryHandler

Type Parameters

THandler

The handler type.

AddTrackableHandler<THandler>()

Adds an handler for trackable queries.

public static void AddTrackableHandler<THandler>() where THandler : ITrackableQueryHandler

Type Parameters

THandler

The handler type.

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

Asynchronously determines whether all the elements of a sequence satisfy a condition.

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

Parameters

source IQueryable<TSource>

Source.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if every element of the source sequence passes the test in the specified predicate; otherwise, false.

Type Parameters

TSource

Data type in the source.

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

Asynchronously determines whether a sequence contains any elements.

public static Task<bool> AnyAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if the source sequence contains any elements; otherwise, false.

Type Parameters

TSource

Data type in the source.

AsNoTracking<TEntity>(IQueryable<TEntity>)

Returns a new query where the entities returned will not be cached.

public static IQueryable<TEntity> AsNoTracking<TEntity>(this IQueryable<TEntity> source) where TEntity : class

Parameters

source IQueryable<TEntity>

The source query.

Returns

IQueryable<TEntity>

The new query.

Type Parameters

TEntity

Type of the entity.

AsSingleQuery<TEntity>(IQueryable<TEntity>)

Returns a new query which is configured to load the collections in the query results in a single database query.

public static IQueryable<TEntity> AsSingleQuery<TEntity>(this IQueryable<TEntity> source) where TEntity : class

Parameters

source IQueryable<TEntity>

The source query.

Returns

IQueryable<TEntity>

A new query where collections will be loaded through single database query.

Type Parameters

TEntity

The type of entity being queried.

AsSplitQuery<TEntity>(IQueryable<TEntity>)

Returns a new query which is configured to load the collections in the query results through separate database queries.

public static IQueryable<TEntity> AsSplitQuery<TEntity>(this IQueryable<TEntity> source) where TEntity : class

Parameters

source IQueryable<TEntity>

The source query.

Returns

IQueryable<TEntity>

A new query where collections will be loaded through separate database queries.

Type Parameters

TEntity

The type of entity being queried.

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

Gets the number of records.

public static Task<int> CountAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<int>

Number of records.

Type Parameters

TSource

Type of data in the source.

ExecuteDeleteAsync<TEntity>(IQueryable<TEntity>, CancellationToken)

Asynchronously deletes database rows for the entity instances which match the LINQ query from the database.

public static Task<int> ExecuteDeleteAsync<TEntity>(this IQueryable<TEntity> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TEntity>

The source query.

cancellationToken CancellationToken

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

Returns

Task<int>

The total number of rows deleted in the database.

Type Parameters

TEntity

The entity type.

ExecuteDelete<TEntity>(IQueryable<TEntity>)

Deletes all database rows for the entity instances which match the LINQ query from the database.

public static int ExecuteDelete<TEntity>(this IQueryable<TEntity> source)

Parameters

source IQueryable<TEntity>

The source query.

Returns

int

The total number of rows deleted in the database.

Type Parameters

TEntity

The entity type.

ExecuteUpdateAsync<TEntity>(IQueryable<TEntity>, Action<UpdateSettersBuilder<TEntity>>, CancellationToken)

Asynchronously updates database rows for the entity instances which match the LINQ query from the database.

public static Task<int> ExecuteUpdateAsync<TEntity>(this IQueryable<TEntity> source, Action<UpdateSettersBuilder<TEntity>> updateSettersBuilder, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TEntity>

The source query.

updateSettersBuilder Action<UpdateSettersBuilder<TEntity>>

A builder to configure the properties to update.

cancellationToken CancellationToken

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

Returns

Task<int>

The total number of rows updated in the database.

Type Parameters

TEntity

The entity type.

ExecuteUpdate<TEntity>(IQueryable<TEntity>, Action<UpdateSettersBuilder<TEntity>>)

Updates all database rows for the entity instances which match the LINQ query from the database.

public static int ExecuteUpdate<TEntity>(this IQueryable<TEntity> source, Action<UpdateSettersBuilder<TEntity>> updateSettersBuilder)

Parameters

source IQueryable<TEntity>

The source query.

updateSettersBuilder Action<UpdateSettersBuilder<TEntity>>

A builder to configure the properties to update.

Returns

int

The total number of rows updated in the database.

Type Parameters

TEntity

The entity type.

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

Gets the first element from the source.

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

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

First element of the source.

Type Parameters

TSource

Type of data in the source.

Exceptions

InvalidOperationException

The source contains no elements.

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

Gets the first element from the source or null.

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

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

First element of the source or null.

Type Parameters

TSource

Type of data in the source.

Include<TEntity, TProperty>(IQueryable<TEntity>, Expression<Func<TEntity, TProperty>>)

Includes a linked property in the query.

public static INeosIncludableQueryable<TEntity, TProperty> Include<TEntity, TProperty>(this IQueryable<TEntity> source, Expression<Func<TEntity, TProperty>> navigationPropertyPath) where TEntity : class

Parameters

source IQueryable<TEntity>

Request source.

navigationPropertyPath Expression<Func<TEntity, TProperty>>

Path of the property to include.

Returns

INeosIncludableQueryable<TEntity, TProperty>

New request.

Type Parameters

TEntity

Type of the requested entity.

TProperty

Type of the property to include.

ResetExecutableQueryHandler()

Resets the handler for executable queries to the default handler.

[ExcludeFromCodeCoverage(Justification = "For testing purposes only.")]
public static void ResetExecutableQueryHandler()

SetExecutableQueryHandler(IExecutableQueryHandler)

Sets the handler for executable queries.

[ExcludeFromCodeCoverage(Justification = "For testing purposes only.")]
public static void SetExecutableQueryHandler(IExecutableQueryHandler handler)

Parameters

handler IExecutableQueryHandler

The handler to set.

Remarks

For testing purposes only.

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

Gets the single element from the source

  • or throw exception if there is not one-and-only-one element.
public static Task<TSource> SingleAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

First element of the source.

Type Parameters

TSource

Type of data in the source.

Exceptions

InvalidOperationException

The source does not contain one-and-only-one element matching the predicate.

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

Gets the single element from the source

  • or null if none found
  • or throw exception if there is more than one element.
public static Task<TSource?> SingleOrDefaultAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource>

Single element of the source or null.

Type Parameters

TSource

Type of data in the source.

Exceptions

InvalidOperationException

The source contains two-or-more elements matching the predicate.

ThenInclude<TEntity, TPreviousProperty, TProperty>(INeosIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>>, Expression<Func<TPreviousProperty, TProperty>>)

Includes a linked property in the query.

public static INeosIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(this INeosIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>> source, Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class

Parameters

source INeosIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>>

Request source.

navigationPropertyPath Expression<Func<TPreviousProperty, TProperty>>

Path of the property to include.

Returns

INeosIncludableQueryable<TEntity, TProperty>

New request.

Type Parameters

TEntity

Type of the requested entity.

TPreviousProperty

Type of previous property included.

TProperty

Type of property to include.

ThenInclude<TEntity, TPreviousProperty, TProperty>(INeosIncludableQueryable<TEntity, TPreviousProperty>, Expression<Func<TPreviousProperty, TProperty>>)

Includes a linked property in the query.

public static INeosIncludableQueryable<TEntity, TProperty> ThenInclude<TEntity, TPreviousProperty, TProperty>(this INeosIncludableQueryable<TEntity, TPreviousProperty> source, Expression<Func<TPreviousProperty, TProperty>> navigationPropertyPath) where TEntity : class

Parameters

source INeosIncludableQueryable<TEntity, TPreviousProperty>

Request source.

navigationPropertyPath Expression<Func<TPreviousProperty, TProperty>>

Path of the property to include.

Returns

INeosIncludableQueryable<TEntity, TProperty>

New request.

Type Parameters

TEntity

Type of the requested entity.

TPreviousProperty

Type of previous property included.

TProperty

Type of the property to include.

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

Gets all the elements from the source as an array.

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

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TSource[]>

Array of source elements.

Type Parameters

TSource

Type of data in the source.

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

Gets all items from source as a list.

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

Parameters

source IQueryable<TSource>

Source.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<List<TSource>>

List of source elements.

Type Parameters

TSource

Type of data in the source.

Where<TEntity, TProperty>(IQueryable<TEntity>, Expression<Func<TEntity, TProperty>>, Expression<Func<TProperty, bool>>?)

Filters a sequence of values based on a predicate.

public static IQueryable<TEntity> Where<TEntity, TProperty>(this IQueryable<TEntity> source, Expression<Func<TEntity, TProperty>> propertyExpression, Expression<Func<TProperty, bool>>? predicate)

Parameters

source IQueryable<TEntity>

The source query.

propertyExpression Expression<Func<TEntity, TProperty>>

The path of the property on which the filter is based.

predicate Expression<Func<TProperty, bool>>

A function to test each element for a condition.

Returns

IQueryable<TEntity>

The updated query.

Type Parameters

TEntity

The entity type.

TProperty

The type of the property on which the filter is based.