Class NeosQueryableExtensions
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
THandlerThe type of manager to add.
AddExecutableHandler<THandler>()
Adds an handler for executable queries.
public static void AddExecutableHandler<THandler>() where THandler : IExecutableQueryHandler
Type Parameters
THandlerThe handler type.
AddIncludableHandler<THandler>()
Adds a handler for requests with inclusion.
public static void AddIncludableHandler<THandler>() where THandler : IIncludableQueryHandler
Type Parameters
THandlerThe type of manager to add.
AddSplittableHandler<THandler>()
Adds an handler for splittable queries.
public static void AddSplittableHandler<THandler>() where THandler : ISplittableQueryHandler
Type Parameters
THandlerThe handler type.
AddTrackableHandler<THandler>()
Adds an handler for trackable queries.
public static void AddTrackableHandler<THandler>() where THandler : ITrackableQueryHandler
Type Parameters
THandlerThe 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
sourceIQueryable<TSource>Source.
predicateExpression<Func<TSource, bool>>A function to test each element for a condition.
cancellationTokenCancellationTokenThe 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
TSourceData 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe 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
TSourceData 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
sourceIQueryable<TEntity>The source query.
Returns
- IQueryable<TEntity>
The new query.
Type Parameters
TEntityType 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
sourceIQueryable<TEntity>The source query.
Returns
- IQueryable<TEntity>
A new query where collections will be loaded through single database query.
Type Parameters
TEntityThe 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
sourceIQueryable<TEntity>The source query.
Returns
- IQueryable<TEntity>
A new query where collections will be loaded through separate database queries.
Type Parameters
TEntityThe 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TSourceType 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
sourceIQueryable<TEntity>The source query.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Type Parameters
TEntityThe 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
sourceIQueryable<TEntity>The source query.
Returns
- int
The total number of rows deleted in the database.
Type Parameters
TEntityThe 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
sourceIQueryable<TEntity>The source query.
updateSettersBuilderAction<UpdateSettersBuilder<TEntity>>A builder to configure the properties to update.
cancellationTokenCancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
Type Parameters
TEntityThe 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
sourceIQueryable<TEntity>The source query.
updateSettersBuilderAction<UpdateSettersBuilder<TEntity>>A builder to configure the properties to update.
Returns
- int
The total number of rows updated in the database.
Type Parameters
TEntityThe 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TSource>
First element of the source.
Type Parameters
TSourceType 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TSource>
First element of the source or null.
Type Parameters
TSourceType 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
sourceIQueryable<TEntity>Request source.
navigationPropertyPathExpression<Func<TEntity, TProperty>>Path of the property to include.
Returns
- INeosIncludableQueryable<TEntity, TProperty>
New request.
Type Parameters
TEntityType of the requested entity.
TPropertyType 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
handlerIExecutableQueryHandlerThe 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TSource>
First element of the source.
Type Parameters
TSourceType 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
nullif 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TSource>
Single element of the source or null.
Type Parameters
TSourceType 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
sourceINeosIncludableQueryable<TEntity, IEnumerable<TPreviousProperty>>Request source.
navigationPropertyPathExpression<Func<TPreviousProperty, TProperty>>Path of the property to include.
Returns
- INeosIncludableQueryable<TEntity, TProperty>
New request.
Type Parameters
TEntityType of the requested entity.
TPreviousPropertyType of previous property included.
TPropertyType 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
sourceINeosIncludableQueryable<TEntity, TPreviousProperty>Request source.
navigationPropertyPathExpression<Func<TPreviousProperty, TProperty>>Path of the property to include.
Returns
- INeosIncludableQueryable<TEntity, TProperty>
New request.
Type Parameters
TEntityType of the requested entity.
TPreviousPropertyType of previous property included.
TPropertyType 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TSource[]>
Array of source elements.
Type Parameters
TSourceType 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
sourceIQueryable<TSource>Source.
cancellationTokenCancellationTokenThe cancellation token.
Returns
Type Parameters
TSourceType 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
sourceIQueryable<TEntity>The source query.
propertyExpressionExpression<Func<TEntity, TProperty>>The path of the property on which the filter is based.
predicateExpression<Func<TProperty, bool>>A function to test each element for a condition.
Returns
- IQueryable<TEntity>
The updated query.
Type Parameters
TEntityThe entity type.
TPropertyThe type of the property on which the filter is based.