Exemple #1
0
        private OrderByColumn <TPoco> CreateByPath(
            IReadOnlyCollection <KeyValuePair <DbClassInfoCache, DbPropertyInfoCache> > columnPath)
        {
            var columnDefinitionPart =
                ConditionalQuery <TPoco> .TraversePropertyPathToColumn(columnPath, ContainerObject);

            ContainerObject.SearchLast <OrderByColumnQueryPart>().Columns.Add(columnDefinitionPart);
            return(new OrderByColumn <TPoco>(this));
        }
Exemple #2
0
        private ConditionalColumnQuery <TPoco> ConditionalColumnQueryByPath(
            IReadOnlyCollection <KeyValuePair <DbClassInfoCache, DbPropertyInfoCache> > columnPath)
        {
            var expression = new ExpressionConditionPart(TraversePropertyPathToColumn(columnPath, ContainerObject));

            ContainerObject.SearchLast <ConditionStatementQueryPart>().Conditions.Add(expression);

            return(new ConditionalColumnQuery <TPoco>(this, expression));
        }
Exemple #3
0
        public SelectQuery <TPoco> SynteticColumn(string column, out QueryIdentifier identifier)
        {
            var selectableQueryPart = ContainerObject.SearchLast <SelectTableQueryPart>();
            var columnInfo          = new ColumnInfo(column, selectableQueryPart.Alias, ContainerObject);

            columnInfo.ColumnIdentifierEntry = ContainerObject.CreateColumnAlias(column);
            identifier = columnInfo.ColumnIdentifierEntry;
            selectableQueryPart._columns.Add(columnInfo);
            return(this);
        }
Exemple #4
0
        /// <summary>
        ///		Sets all Conditional expressions in ()
        /// </summary>
        /// <param name="operation"></param>
        /// <returns></returns>
        public ConditionalEvalQuery <TPoco> InBracket(Func <ConditionalQuery <TPoco>, ConditionalEvalQuery <TPoco> > operation)
        {
            var expression = new ConditionStructurePart(ConditionStructurePart.LogicalOperator.OpenBracket);

            ContainerObject.SearchLast <ConditionStatementQueryPart>().Conditions.Add(expression);
            var result = operation(this);

            result.ContainerObject.SearchLast <ConditionStatementQueryPart>().Conditions.Add(new ConditionStructurePart(ConditionStructurePart.LogicalOperator.CloseBracket));
            return(result);
        }
Exemple #5
0
        /// <summary>
        ///     Appents another order statement
        /// </summary>
        /// <param name="columnName">Name of the column.</param>
        /// <returns></returns>
        public OrderByColumn <TPoco> ThenBy(string columnName)
        {
            var columnInfos = ContainerObject.SearchLast <ISelectableQueryPart>()
                              .Columns.ToArray();
            var columnDefinitionPart = columnInfos.FirstOrDefault(e => e.IsEquivalentTo(columnName));

            if (columnDefinitionPart == null)
            {
                throw new InvalidOperationException($"You have tried to create an expression for the column '{columnName}' on table '{typeof(TPoco)}' that does not exist.");
            }

            ContainerObject.SearchLast <OrderByColumnQueryPart>().Columns.Add(columnDefinitionPart);
            return(new OrderByColumn <TPoco>(this));
        }
Exemple #6
0
        /// <summary>
        ///     Executes the Current QueryBuilder by setting the type
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns></returns>
        public IDataPager <TPoco> ForPagedResult(int page, int pageSize)
        {
            if (ContainerObject.SearchLast <OrderByColumnQueryPart>() == null)
            {
                throw new InvalidOperationException("To use the Pagination you have to define an Order.By()");
            }

            var pager = ContainerObject.AccessLayer.Database.CreatePager <TPoco>();

            pager.CommandQuery = this;
            pager.PageSize     = pageSize;
            pager.CurrentPage  = page;
            pager.LoadPage(ContainerObject.AccessLayer);
            return(pager);
        }
Exemple #7
0
        /// <summary>
        ///     Creates an Statement based on this query to select a Subset of rows by Limit
        /// </summary>
        /// <param name="limit"></param>
        /// <returns></returns>
        public virtual ElementProducer <TPoco> LimitBy(int limit)
        {
            switch (ContainerObject.AccessLayer.DbAccessType)
            {
            case DbAccessType.MsSql:
                ContainerObject.SearchLast <ISelectableQueryPart>().Limit = limit;
                break;

            case DbAccessType.SqLite:
            case DbAccessType.MySql:
                var elementProducer = new RootQuery(ContainerObject.AccessLayer)
                                      .WithCte(this, out var cteId)
                                      .Select.Identifier <TPoco>(cteId)
                                      .Add(new LimitByQueryPart(limit));

                return(new ElementProducer <TPoco>(elementProducer));
            }
            return(new ElementProducer <TPoco>(this));
        }
        /// <summary>
        ///     Creates an Statement based on this query to select a Subset of rows by Limit
        /// </summary>
        /// <param name="limit"></param>
        /// <returns></returns>
        public virtual ElementProducer <TPoco> LimitBy(int limit)
        {
            if (ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.MsSql))
            {
                ContainerObject.SearchLast <ISelectableQueryPart>().Limit = limit;
            }
            else if (ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.SqLite) ||
                     ContainerObject.AccessLayer.DbAccessType.HasFlag(DbAccessType.MySql))
            {
                var elementProducer = new RootQuery(ContainerObject.AccessLayer)
                                      .WithCte(this, out var cteId)
                                      .Select.Identifier <TPoco>(cteId)
                                      .Add(new LimitByQueryPart(limit));

                return(new ElementProducer <TPoco>(elementProducer));
            }

            return(new ElementProducer <TPoco>(this));
        }
Exemple #9
0
 public SelectQuery <TPoco> Distinct()
 {
     ContainerObject.SearchLast <ISelectableQueryPart>().Distinct = true;
     return(this);
 }