2018-12-07 00:10:33 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2019-02-13 21:01:47 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore.Query.Internal;
|
2018-12-07 00:10:33 -05:00
|
|
|
|
using PoweredSoft.Data.Core;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace PoweredSoft.Data.EntityFrameworkCore
|
|
|
|
|
{
|
2019-02-13 21:01:47 -05:00
|
|
|
|
public class AsyncQueryableHandlerService : IAsyncQueryableHandlerService
|
2018-12-07 00:10:33 -05:00
|
|
|
|
{
|
|
|
|
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
|
public Task<T> FirstOrDefaultAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.FirstOrDefaultAsync(predicate, cancellationToken);
|
|
|
|
|
public Task<List<T>> ToListAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.ToListAsync(cancellationToken);
|
|
|
|
|
public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.CountAsync();
|
|
|
|
|
public Task<long> LongCountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.LongCountAsync();
|
2019-02-13 21:01:47 -05:00
|
|
|
|
|
|
|
|
|
public bool CanHandle<T>(IQueryable<T> queryable) => queryable.Provider is IAsyncQueryProvider;
|
|
|
|
|
|
|
|
|
|
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.AnyAsync(predicate, cancellationToken);
|
|
|
|
|
|
|
|
|
|
public Task<bool> AnyAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken = default(CancellationToken))
|
|
|
|
|
=> queryable.AnyAsync(cancellationToken);
|
2018-12-07 00:10:33 -05:00
|
|
|
|
}
|
|
|
|
|
}
|