Ejemplo n.º 1
0
        /// <summary>
        /// 执行指定表达式树所表示的查询。
        /// </summary>
        /// <typeparam name="TResult">执行查询所生成的值的类型。</typeparam>
        /// <param name="expression">表示 LINQ 查询的表达式树</param>
        /// <returns></returns>
        public TResult Execute <TResult>(Expression expression)
        {
            if (!ExecuteCache.CanCache(expression))
            {
                return((TResult)entityQueryProvider.Execute(expression));
            }

            return(ExecuteCache.TryGet(expression, () => (TResult)entityQueryProvider.Execute(expression)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 异步的,执行指定表达式树所表示的查询。
        /// </summary>
        /// <typeparam name="TResult">执行查询所生成的值的类型。</typeparam>
        /// <param name="expression">一个表示的表达式树 LINQ 查询。</param>
        /// <param name="cancellationToken">取消操作的通知。</param>
        /// <returns></returns>
        public async Task <TResult> ExecuteAsync <TResult>(Expression expression, CancellationToken cancellationToken)
        {
            if (!ExecuteCache.CanCache(expression))
            {
                return(await entityQueryProvider.ExecuteAsync <TResult>(expression));
            }

            return(await ExecuteCache.TryGet(expression, () => entityQueryProvider.ExecuteAsync <TResult>(expression, cancellationToken)));
        }
Ejemplo n.º 3
0
 public IAsyncEnumerable <TResult> ExecuteEnumerableAsync <TResult>(Expression expression, CancellationToken cancellationToken)
 {
     if (!ExecuteCache.CanCache(expression))
     {
         return(entityQueryProvider.ExecuteEnumerableAsync <TResult>(expression, cancellationToken));
     }
     else
     {
         return(ExecuteCache.TryGet(expression, () => entityQueryProvider.ExecuteEnumerableAsync <TResult>(expression, cancellationToken)));
     }
 }
Ejemplo n.º 4
0
 private IList <T> ExecuteList()
 {
     if (list == null)
     {
         if (provider == null)
         {
             list = new List <T>();
         }
         else
         {
             list = ExecuteCache.TryGet(expression, () => provider.Execute <IEnumerable <T> >(expression)?.ToList());
         }
     }
     return(list);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 执行指定表达式树所表示的查询。
 /// </summary>
 /// <param name="expression">表示 LINQ 查询的表达式树</param>
 /// <returns></returns>
 public object Execute(Expression expression)
 {
     ExecuteCache.TryExpire(expression);
     return(entityQueryProvider.Execute(expression));
 }