Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
        /// <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));
        }