예제 #1
0
        private TableQuery <T> AddOrderBy <U>(Expression <Func <T, U> > orderExpr, bool asc)
        {
            if (orderExpr.NodeType == ExpressionType.Lambda)
            {
                LambdaExpression lambda = orderExpr;

                MemberExpression mem = null;

                UnaryExpression unary = lambda.Body as UnaryExpression;
                if (unary != null && unary.NodeType == ExpressionType.Convert)
                {
                    mem = unary.Operand as MemberExpression;
                }
                else
                {
                    mem = lambda.Body as MemberExpression;
                }

                if (mem != null && mem.Expression.NodeType == ExpressionType.Parameter)
                {
                    TableQuery <T> q = Clone <T>();
                    if (q._orderBys == null)
                    {
                        q._orderBys = new List <Ordering>();
                    }
                    q._orderBys.Add(new Ordering
                    {
                        ColumnName = this.Table.FindColumnWithPropertyName(mem.Member.Name).Name,
                        Ascending  = asc
                    });
                    return(q);
                }

                throw new NotSupportedException("Order By does not support: " + orderExpr);
            }

            throw new NotSupportedException("Must be a predicate");
        }
예제 #2
0
        public TableQuery <U> Clone <U>()
        {
            TableQuery <U> ins = new TableQuery <U>(this._conn, this.Table);

            ins._where    = _where;
            ins._deferred = _deferred;
            if (_orderBys != null)
            {
                ins._orderBys = new List <Ordering>(_orderBys);
            }
            ins._betweenBy = _betweenBy;
            ins._limit     = _limit;
            ins._offset    = _offset;
            //Select
            ins._selector = _selector;
            //Join
            ins._joinInner            = _joinInner;
            ins._joinInnerKeySelector = _joinInnerKeySelector;
            ins._joinOuter            = _joinOuter;
            ins._joinOuterKeySelector = _joinOuterKeySelector;
            ins._joinSelector         = _joinSelector;

            return(ins);
        }
예제 #3
0
        public T FirstOrDefault()
        {
            TableQuery <T> query = Take(1);

            return(query.ToList().FirstOrDefault());
        }