Beispiel #1
0
        protected override void SelectStatement()
        {
            var primaryTable = EntityTableCacheHelper.TryGetTable <TData>();
            var selectTable  = (SelectType != typeof(TData)) ? EntityTableCacheHelper.TryGetTable(SelectType) : primaryTable;

            _selectStatement = new StringBuilder();

            _selectStatement.Append("SELECT ");

            if (TopCount > 0 && SkipCount == 0)
            {
                _selectStatement.Append("TOP(" + TopCount + ") ");
            }

            if (IsDistinct)
            {
                _selectStatement.Append("DISTINCT ");
            }

            if (IsCount)
            {
                _selectStatement.Append("COUNT(*) ");
            }
            else
            {
                for (int i = 0; i < selectTable.Columns.Count; i++)
                {
                    var x = selectTable.Columns.ElementAt(i);
                    _selectStatement.Append($"{selectTable.Identifier}.{StartQuotationMark}{x.Value.ColumnName}{EndQuotationMark}");

                    if ((i + 1) != selectTable.Columns.Count)
                    {
                        _selectStatement.Append(",");
                    }

                    _selectStatement.Append(" ");
                }
            }

            _selectStatement.Append($"FROM {StartQuotationMark}{primaryTable.Name}{EndQuotationMark} {primaryTable.Identifier}");
            _selectStatement.Append(WriteClause());

            if (TopCount <= 0 || SkipCount <= 0)
            {
                return;
            }
            if (string.IsNullOrEmpty(_orderBy.ToString()))
            {
                //primaryTable.Columns
                var order = new StringBuilder();
                order.Append(string.Join(
                                 ",",
                                 primaryTable.Columns.Where(t => t.Value.PrimaryKey).Select(t =>
                                                                                            $"{primaryTable.Identifier}.{StartQuotationMark}{t.Value.ColumnName}{EndQuotationMark}")
                                 ));
                order.Append(" ASC ");
                _orderBy.Insert(0, order);
            }
            _selectStatement.Append(" offset " + SkipCount + " rows fetch next " + TopCount + " rows only");
        }
Beispiel #2
0
        protected override void SelectStatement()
        {
            var primaryTable = EntityTableCacheHelper.TryGetTable <TData>();
            var selectTable  = (SelectType != typeof(TData)) ? EntityTableCacheHelper.TryGetTable(SelectType) : primaryTable;

            _selectStatement = new StringBuilder();

            _selectStatement.Append("SELECT ");

            if (IsDistinct)
            {
                _selectStatement.Append("DISTINCT ");
            }

            if (IsCount)
            {
                _selectStatement.Append("COUNT(*) ");
            }
            else
            {
                for (int i = 0; i < selectTable.Columns.Count; i++)
                {
                    var x = selectTable.Columns.ElementAt(i);
                    _selectStatement.Append($"{selectTable.Identifier}.{StartQuotationMark}{x.Value.ColumnName}{EndQuotationMark}");

                    if ((i + 1) != selectTable.Columns.Count)
                    {
                        _selectStatement.Append(",");
                    }

                    _selectStatement.Append(" ");
                }
            }

            _selectStatement.Append($"FROM {StartQuotationMark}{primaryTable.Name}{EndQuotationMark} {primaryTable.Identifier}");
            _selectStatement.Append(WriteClause());

            if (TopCount <= 0)
            {
                return;
            }
            if (SkipCount > 0)
            {
                _selectStatement.Append(" LIMIT " + SkipCount + " , " + TopCount + " ");
            }
            else
            {
                _selectStatement.Append(" LIMIT " + TopCount + " ");
            }
        }
Beispiel #3
0
 private EntityTable GetTypeProperties()
 {
     return(EntityTableCacheHelper.ToEntityTable(typeof(TData)));
 }