Exemple #1
0
        private string build <TEntity>(Count <TEntity> countQuery)
        {
            var table     = _tableResolver.Resolve <TEntity>();
            var keyColumn = table.PrimaryKeyColumn;
            var query     = countQuery.Query;

            if (query.TakeCount == null && query.SkipCount != null)
            {
                throw new InvalidOperationException("SQLite is not Support (TakeCount == null && SkipCount != null)");
            }

            var strb = new StringBuilder();

            strb.Append("SELECT COUNT(").AppendSql(keyColumn).Append(") ");

            strb.Append(" FROM ").AppendSql(table);

            if (query.Where != null)
            {
                strb.Append(" WHERE ").AppendSql(query.Where);
            }

            if (query.TakeCount != null)
            {
                strb.Append(" LIMIT ").Append(query.TakeCount.Value);
                if (query.SkipCount != null)
                {
                    strb.Append(" OFFSET ").Append(query.SkipCount.Value);
                }
            }

            return(strb.ToString());
        }
Exemple #2
0
        private string build <TEntity>(Count <TEntity> countQuery)
        {
            var table     = _tableResolver.Resolve <TEntity>();
            var keyColumn = table.PrimaryKeyColumn;
            var query     = countQuery.Query;

            var strb = new StringBuilder();

            strb.Append("SELECT COUNT(").AppendSql(keyColumn).Append(") ");

            strb.Append(" FROM ").AppendSql(table);

            if (query.Where != null)
            {
                strb.Append(" WHERE ").AppendSql(query.Where);
            }

            if (query.SkipCount != null || query.TakeCount != null)
            {
                strb.Append(" OFFSET ").Append(query.SkipCount ?? 0).Append(" ROWS");
            }
            if (query.TakeCount != null)
            {
                strb.Append(" FETCH NEXT ").Append(query.TakeCount.Value).Append(" ROWS ONLY");
            }

            return(strb.ToString());
        }
Exemple #3
0
 private IRepository <TEntity> createRepository <TEntity>()
 => new Repository <TEntity>(this, _sqlBuilder, new TableReader <TEntity>(_tableResolver.Resolve <TEntity>()));