예제 #1
0
        public virtual async Task <List <T> > GetByQueryAsync(QueryBase <T> query)
        {
            var condition = TenantCondition.And(query.GetQueryWhere());

            query.RecordCount = await DbSet.Where(condition).CountAsync();

            if (query.RecordCount < 1)
            {
                query.Result = new List <T>();
            }
            else
            {
                if (query.QueryFields.Any())
                {
                    //临时方法,待改进,不科学的方法
                    query.Result =
                        await Task.Run(() =>
                                       DbSet
                                       .Where(condition)
                                       .SelectProperties(query.QueryFields)
                                       .OrderByDescending(query.OrderBy) //暂时取消排序
                                       .Skip(query.PageStart)
                                       .Take(query.PageSize)
                                       .ToList());
                }
                else
                {
                    query.Result = await DbSet
                                   .Where(condition)
                                   .OrderByDescending(query.OrderBy) //暂时取消排序
                                   .Skip(query.PageStart)
                                   .Take(query.PageSize)
                                   .ToListAsync();
                }
            }

            return(query.Result);
        }