public static async Task <bool> AnyAsyncOk <T>( this IQueryable <T> query, CancellationToken cancellationToken = default) => query.Provider.GetType() == typeof(NHibernate.Linq.DefaultQueryProvider) ? await LinqExtensionMethods.AnyAsync(query, cancellationToken) : query.Any();
protected override Expression VisitConstant(ConstantExpression node) { if (node.Type == typeof(TimeSpan)) { return(Expression.Call(ReflectHelper.GetMethod(() => LinqExtensionMethods.MappedAs <object>(null, null)).GetGenericMethodDefinition().MakeGenericMethod(typeof(TimeSpan)), node, Expression.Constant(NHibernateUtil.TimeSpan))); } return(base.VisitConstant(node)); }
public static async Task <T> SingleOrDefaultAsyncOk <T>( this IQueryable <T> query, Expression <Func <T, bool> > predicate, CancellationToken cancellationToken = default) => query.Provider.GetType() == typeof(NHibernate.Linq.DefaultQueryProvider) ? await LinqExtensionMethods.SingleOrDefaultAsync(query, predicate, cancellationToken) : query.SingleOrDefault(predicate);
private Task <IList> ToListAsync(dynamic queryable, CancellationToken cancellationToken) { return(queryable is INhQueryProvider?ToListAsyncInternal() : Task.FromResult <IList>(ToList(queryable))); async Task <IList> ToListAsyncInternal() { return(await LinqExtensionMethods.ToListAsync(queryable, cancellationToken)); } }
public void ItShouldThrowOnCacheableWithDirectWithOptionsCall() { Action act = () => LinqExtensionMethods.WithOptions(Enumerable.Empty <PersonEntity>().AsQueryable(), options => options.SetCacheable(true)).FirstOrDefault(); act.Should() .Throw <NotSupportedException>() .WithMessage( "The query.Provider does not support setting options. Please implement IQueryProviderWithOptions."); }
public void ItShouldThrowOnCacheableWithDirectCacheableCall() { Action act = () => LinqExtensionMethods.Cacheable(Enumerable.Empty <PersonEntity>().AsQueryable()).FirstOrDefault(); act.Should() .Throw <InvalidOperationException>() .WithMessage( "There is no method 'Cacheable' on type 'NHibernate.Linq.LinqExtensionMethods' that matches the specified arguments"); }
static QueryFilterAttribute() { ToFutureMethod = ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.ToFuture <object>(null)) .GetGenericMethodDefinition(); ToFutureValueMethod = ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.ToFutureValue <object, object>(null, null)) .GetGenericMethodDefinition(); GetCountExpressionMethod = ReflectHelper.GetMethodDefinition <QueryFilterAttribute>(o => o.GetCountExpression <object>()) .GetGenericMethodDefinition(); }
public void ItShouldThrowOnTimeoutWithDirectTimeoutCall() { #pragma warning disable 618 Action act = () => LinqExtensionMethods.Timeout(Enumerable.Empty <PersonEntity>().AsQueryable(), 1000).FirstOrDefault(); #pragma warning restore 618 act.Should() .Throw <NotSupportedException>() .WithMessage( "The query.Provider does not support setting options. Please implement IQueryProviderWithOptions."); }
public static IQueryable <T> CacheableOk <T>(this IQueryable <T> query) { if (query.Provider.GetType() == typeof(NHibernate.Linq.DefaultQueryProvider)) { query = LinqExtensionMethods.WithOptions( query, o => { o.SetCacheable(true); }); } return(query); }
/// <summary> /// Gets the result of a getter-expression from the query, but lazily so /// that the data-source will not be contacted until the value is retrieved. /// </summary> /// <returns>The lazy value.</returns> /// <param name="query">The query.</param> /// <typeparam name="T">The type of object queried.</typeparam> public Lazy <T> GetLazyValue <T>(IQueryable <T> query) { if (query == null) { throw new ArgumentNullException(nameof(query)); } if (!(query.Provider is NhQueryProvider)) { throw new ArgumentException($"The query provider must be an instance of {typeof(NhQueryProvider).FullName}.", nameof(query)); } var futureValue = LinqExtensionMethods.ToFutureValue(query); return(new Lazy <T>(() => futureValue.Value)); }
public void RemoveCommonItems_When_common_and_sequence_becomes_empty() { int[] s1 = { 1, 2 }; int[] s2 = { 4, 2, 6, 8, 1 }; int[] s3 = { 10, 21, 2, 1 }; var res = LinqExtensionMethods.RemoveCommonItems(s1, s2, s3); Assert.AreEqual(3, res.Length); Assert.AreNotEqual(s1, res[0]); Assert.AreNotEqual(s2, res[1]); Assert.AreNotEqual(s3, res[2]); Assert.IsTrue(res[0].SequenceEqual(new int[0])); Assert.IsTrue(res[1].SequenceEqual(new[] { 4, 6, 8 })); Assert.IsTrue(res[2].SequenceEqual(new[] { 10, 21 })); }
public void RemoveCommonItems_When_no_common() { int[] s1 = { 1, 2 }; int[] s2 = { 4, 6, 8 }; int[] s3 = { 10, 21 }; var res = LinqExtensionMethods.RemoveCommonItems(s1, s2, s3); Assert.AreEqual(3, res.Length); Assert.AreNotEqual(s1, res[0]); Assert.AreNotEqual(s2, res[1]); Assert.AreNotEqual(s3, res[2]); Assert.IsTrue(s1.SequenceEqual(res[0])); Assert.IsTrue(s2.SequenceEqual(res[1])); Assert.IsTrue(s3.SequenceEqual(res[2])); }
public Task <long> CountAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken)) => LinqExtensionMethods.LongCountAsync(source, cancellationToken);
public IEnumerable <T> ToFuture <T>(IQueryable <T> queryable) { var query = LinqExtensionMethods.ToFuture(queryable); return(query); }
public Task <List <TSource> > ToListAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken)) => LinqExtensionMethods.ToListAsync(source, cancellationToken);
public Task <TSource> SingleOrDefaultAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default(CancellationToken)) => LinqExtensionMethods.SingleOrDefaultAsync(source, cancellationToken);
public Task <TSource> SingleOrDefaultAsync <TSource>(IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate, CancellationToken cancellationToken = default(CancellationToken)) => LinqExtensionMethods.SingleOrDefaultAsync(source, predicate, cancellationToken);
public Task <TResult> MinAsync <TSource, TResult>(IQueryable <TSource> source, Expression <Func <TSource, TResult> > selector, CancellationToken cancellationToken = default(CancellationToken)) => LinqExtensionMethods.MinAsync(source, selector, cancellationToken);
public Task <TSource> FirstOrDefaultAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default) { return(LinqExtensionMethods.FirstOrDefaultAsync(source, cancellationToken)); }
public virtual IQueryable <T> GetAll() { return(LinqExtensionMethods.Query <T>(this.Session)); }
public Task <bool> AnyAsync <TSource>(IQueryable <TSource> source, CancellationToken cancellationToken = default) { return(LinqExtensionMethods.AnyAsync(source, cancellationToken)); }
public Task <TSource> FirstOrDefaultAsync <TSource>(IQueryable <TSource> source, Expression <Func <TSource, bool> > predicate, CancellationToken cancellationToken = default) { return(LinqExtensionMethods.FirstOrDefaultAsync(source, predicate, cancellationToken)); }