Пример #1
0
        IIncludeMany <T> IIncludeSession.Many <T>(SqlQuery sqlQuery)
        {
            if (sqlQuery == null)
            {
                throw new ArgumentNullException("sqlQuery");
            }

            var include = new IncludeMany <T>();

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

            return(include);
        }
Пример #2
0
        public async Task <IList <T> > FetchAsync <T>(SqlQuery sqlQuery, CancellationToken cancellationToken)
        {
            this.ThrowIfDisposed();

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

            var include = new IncludeMany <T>();

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

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

            return(include.Values);
        }
Пример #3
0
        public IList <T> Fetch <T>(SqlQuery sqlQuery)
        {
            this.ThrowIfDisposed();

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

            var include = new IncludeMany <T>();

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

            this.ExecutePendingQueries();

            return(include.Values);
        }
Пример #4
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));
        }