Beispiel #1
0
        public async Task <Operation <IPage <TObject> > > GetAsync(string query         = null, SortOptions sort    = null,
                                                                   PageOptions page     = null, FieldOptions fields = null,
                                                                   FilterOptions filter = null, ProjectionOptions projection = null)
        {
            _db.SetTypeInfo(typeof(TObject));

            if (sort == null || sort == SortOptions.Empty)
            {
                sort = SortOptions.FromType <TObject>(x => x.Id);
            }

            if (page == null || page == PageOptions.Empty)
            {
                page = new PageOptions {
                    Page = 1, PerPage = _options.CurrentValue.PerPageDefault
                }
            }
            ;

            var sql  = _dialect.Build <TObject>(sort, fields, filter, projection);
            var data = (await _db.Current.QueryAsync <TObject>(PageBuilder.Page(_dialect, sql),
                                                               new { page.Page, page.PerPage })).AsList();
            var total = await _db.Current.ExecuteScalarAsync <long>(_dialect.Count(_descriptor, filter?.Fields));

            var slice = new Page <TObject>(data, data.Count, page.Page - 1, page.PerPage, total);

            return(new Operation <IPage <TObject> >(slice));
        }
Beispiel #2
0
        public virtual async Task <Operation <IPage <Person> > > GetAsync(string query = null, SortOptions sort = null, PageOptions page = null, FieldOptions fields = null, FilterOptions filter = null, ProjectionOptions projection = null)
        {
            _db.SetTypeInfo(typeof(Person));
            if (sort == SortOptions.Empty)
            {
                sort = DefaultSort;
            }

            // SELECT * FROM X WHERE Y ORDER BY Z...
            var sql = _dialect.Build <Person>(sort, fields, filter, projection);

            // FETCH OFFSET...
            var data = await _db.Current.QueryAsync <Person>(PageBuilder.Page(_dialect, sql), new { page.Page, page.PerPage });

            // SELECT COUNT(1) WHERE ...
            var total = await _db.Current.ExecuteScalarAsync <long>(_dialect.Count <Person>(_descriptor, filter));

            var slice = new Page <Person>(data, data.Count(), page.Page - 1, page.PerPage, total);

            return(new Operation <IPage <Person> >(slice));
        }