Exemplo n.º 1
0
        IInclude <T> IIncludeSession.Scalar <T>(SqlQuery sqlQuery)
        {
            if (sqlQuery == null)
            {
                throw new ArgumentNullException("sqlQuery");
            }

            var include = new IncludeScalar <T>();

            this.includes.Enqueue(include);
            this.queries.Enqueue(sqlQuery);

            return(include);
        }
Exemplo n.º 2
0
        public async Task <PagedResult <T> > PagedAsync <T>(SqlQuery sqlQuery, PagingOptions pagingOptions, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

            if (sqlQuery == null)
            {
                throw new ArgumentNullException("sqlQuery");
            }

            if (pagingOptions == PagingOptions.None)
            {
                throw new MicroLiteException(ExceptionMessages.Session_PagingOptionsMustNotBeNone);
            }

            var includeCount = new IncludeScalar <int>();

            this.includes.Enqueue(includeCount);

            var countSqlQuery = this.SqlDialect.CountQuery(sqlQuery);

            this.queries.Enqueue(countSqlQuery);

            var includeMany = new IncludeMany <T>();

            this.includes.Enqueue(includeMany);

            var pagedSqlQuery = this.SqlDialect.PageQuery(sqlQuery, pagingOptions);

            this.queries.Enqueue(pagedSqlQuery);

            await this.ExecutePendingQueriesAsync(cancellationToken).ConfigureAwait(false);

            var page = (pagingOptions.Offset / pagingOptions.Count) + 1;

            return(new PagedResult <T>(page, includeMany.Values, pagingOptions.Count, includeCount.Value));
        }