示例#1
0
        public List <TDocument> Search(Expression <Func <TDocument, bool> > filter, MongoPager pager = null)
        {
            if (filter == null)
            {
                return(null);
            }

            var docs = GetCollection();
            var task = docs.Find <TDocument>(filter);

            if (pager != null)
            {
                task = task.Skip((pager.PageNo - 1) * pager.PageSize).Limit(pager.PageSize);
            }

            var taskResult = task.ToListAsync();

            taskResult.Wait();

            return(taskResult.Result);
        }
示例#2
0
        public List <TOutput> Search <TOutput>(Expression <Func <TOutput, bool> > filter, MongoPager pager = null) where TOutput : TDocument
        {
            if (filter == null)
            {
                return(null);
            }

            var docs = GetCollection <TOutput>();
            var task = docs.Find <TOutput>(filter);

            if (pager != null)
            {
                task = task.Skip((pager.PageNo - 1) * pager.PageSize).Limit(pager.PageSize);
            }

            var taskResult = task.ToListAsync();

            taskResult.Wait();

            return(taskResult.Result);
            //泛型列表向下转型例子
            //List<TOutput> outputList = docList.ConvertAll<TOutput>(new Converter<TDocument, TOutput>(o => (o as TOutput)));
        }