示例#1
0
        /// <summary>
        /// 执行 <see cref="Expression"/> 的查询,返回查询结果。
        /// </summary>
        /// <param name="expression">表示 LINQ 查询的表达式树。</param>
        /// <returns>单值对象。</returns>
        /// <exception cref="TranslateException">对 LINQ 表达式解析失败时抛出此异常。</exception>
        public object Execute(Expression expression)
        {
            var efn = TranslateCache.TryGet(expression, () => (Expression <Func <IDatabase, object> >)GetExecutionPlan(expression));

            var func = efn.Compile();

            return(func(context.Database));
        }
示例#2
0
        /// <summary>
        /// 执行 <see cref="Expression"/> 的查询,返回查询结果。
        /// </summary>
        /// <param name="expression">表示 LINQ 查询的表达式树。</param>
        /// <returns>单值对象。</returns>
        /// <exception cref="TranslateException">对 LINQ 表达式解析失败时抛出此异常。</exception>
        public object Execute(Expression expression)
        {
            var efn = TranslateCache.TryGetDelegate(expression, () => (LambdaExpression)GetExecutionPlan(expression));

            if (efn.Method.GetParameters().Length == 2)
            {
                return(efn.DynamicInvoke(service.Database));
            }

            var segment = SegmentFinder.Find(expression);

            return(efn.DynamicInvoke(service.Database, segment));
        }
示例#3
0
        /// <summary>
        /// 执行 <see cref="Expression"/> 的查询,返回查询结果。
        /// </summary>
        /// <param name="expression">表示 LINQ 查询的表达式树。</param>
        /// <returns>单值对象。</returns>
        /// <exception cref="TranslateException">对 LINQ 表达式解析失败时抛出此异常。</exception>
        public object Execute(Expression expression)
        {
            var efn = TranslateCache.TryGetDelegate(expression, () => (LambdaExpression)GetExecutionPlan(expression));

            var attrs = GetMethodAttributes(efn.Method);

            if (!attrs.Item2)
            {
                return(efn.DynamicInvoke(service.Database));
            }

            var segment = SegmentFinder.Find(expression);

            return(efn.DynamicInvoke(service.Database, segment));
        }
示例#4
0
        /// <summary>
        /// 执行 <see cref="Expression"/> 的查询,返回查询结果。
        /// </summary>
        /// <param name="expression">表示 LINQ 查询的表达式树。</param>
        /// <returns>单值对象。</returns>
        /// <exception cref="TranslateException">对 LINQ 表达式解析失败时抛出此异常。</exception>
        public async Task <TResult> ExecuteAsync <TResult>(Expression expression, CancellationToken cancellationToken = default)
        {
            var efn = TranslateCache.TryGetDelegate(expression, () => (LambdaExpression)GetExecutionPlan(expression));

            var attrs = GetMethodAttributes(efn.Method);

            object result;

            if (attrs.Item1)
            {
                if (attrs.Item2)
                {
                    var segment = SegmentFinder.Find(expression);
                    result = efn.DynamicInvoke(service.Database, segment, cancellationToken);
                }
                else
                {
                    result = efn.DynamicInvoke(service.Database, cancellationToken);
                }
            }
            else
            {
                if (attrs.Item2)
                {
                    var segment = SegmentFinder.Find(expression);
                    result = efn.DynamicInvoke(service.Database, segment);
                }
                else
                {
                    result = efn.DynamicInvoke(service.Database);
                }
            }

            if (result is TResult)
            {
                return((TResult)result);
            }
            else if (result is Task <TResult> task)
            {
                return(task.Result);
            }

            return(default);