コード例 #1
0
ファイル: SAPTable.cs プロジェクト: shuicheng9/sap_interface
        public TResult Execute <TResult>(System.Linq.Expressions.Expression expression)
        {
            SAPTable <TResult> table = (SAPTable <TResult>) this.CreateQuery <TResult>(expression);

            if (table._count && (typeof(TResult) == typeof(int)))
            {
                return((TResult)table.GetResultsCount());
            }
            if (typeof(TResult) == typeof(TEntity))
            {
                return((TResult)table.GetResultsSingle());
            }
            if (typeof(TResult) != typeof(IEnumerable <TEntity>))
            {
                throw new NotSupportedException("The given expression cannot be evaluated and executed");
            }
            return((TResult)table.GetResults());
        }
コード例 #2
0
ファイル: SAPTable.cs プロジェクト: shuicheng9/sap_interface
        public IQueryable <TElement> CreateQuery <TElement>(System.Linq.Expressions.Expression expression)
        {
            SAPTable <TElement> table = new SAPTable <TElement>(this.Connection, this.Log)
            {
                _query                  = this._query,
                _skip                   = this._skip,
                _take                   = this._take,
                _orderBy                = this._orderBy,
                _projection             = this._projection,
                _properties             = this._properties,
                _originalType           = this._originalType,
                _useMultibyteExtraction = this._useMultibyteExtraction,
                _SAPDataContext         = this._SAPDataContext,
                _count                  = this._count,
                _first                  = this._first,
                _firstOrDefault         = this._firstOrDefault,
                _last                   = this._last,
                _lastOrDefault          = this._lastOrDefault
            };
            MethodCallExpression expression2 = expression as MethodCallExpression;

            if (expression2 == null)
            {
                throw new NotSupportedException(expression.ToString());
            }
            switch (expression2.Method.Name)
            {
            case "Where":
                table.BuildQuery(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression);
                return(table);

            case "Select":
                table.BuildProjection(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression);
                return(table);

            case "Take":
                table._take = Convert.ToInt32(((ConstantExpression)expression2.Arguments[1]).Value);
                return(table);

            case "Skip":
                table._skip = Convert.ToInt32(((ConstantExpression)expression2.Arguments[1]).Value);
                return(table);

            case "OrderBy":
                table.BuildOrderBy(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression, false);
                return(table);

            case "OrderByDescending":
                table.BuildOrderBy(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression, true);
                return(table);

            case "ThenBy":
                table.BuildOrderBy(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression, false);
                return(table);

            case "ThenByDescending":
                table.BuildOrderBy(((UnaryExpression)expression2.Arguments[1]).Operand as LambdaExpression, true);
                return(table);

            case "Count":
                table._count = true;
                return(table);

            case "First":
                table._first = true;
                return(table);

            case "FirstOrDefault":
                table._firstOrDefault = true;
                return(table);

            case "Last":
                table._last = true;
                return(table);

            case "LastOrDefault":
                table._lastOrDefault = true;
                return(table);
            }
            throw new NotSupportedException("Unsupported method detected: " + expression2.Method.Name);
        }