/// <summary> /// 查询字符串,返回name 字段匹配keyWord的集合 /// </summary> /// <param name="pageIndex">当前页数</param> /// <param name="pageCount">总页数</param> /// <returns></returns> public List <BsonDocument> QuickSearch(int pageIndex, out int pageCount, List <string> keyFieldList, string keyWord) { var hitList = new List <BsonDocument>(); MongoCursor <BsonDocument> hitQuery = GetBsonDocument(); IQueryable <BsonDocument> resultQuery = null; if (hitQuery != null) { resultQuery = hitQuery.AsQueryable(); if (!string.IsNullOrEmpty(keyWord)) { foreach (var keyField in keyFieldList) { hitList.AddRange(Search(pageIndex, out pageCount, resultQuery.Where(c => c.Text(keyField).Trim().Contains(keyWord.Trim())))); } } else { hitList.AddRange(Search(pageIndex, out pageCount, resultQuery)); } var finalResult = hitList.Distinct(); pageCount = GetPageCount(_pageSize, _totalPages); this._totalPages = finalResult.Count(); return(finalResult.ToList()); } return(Search(pageIndex, out pageCount, hitQuery)); }
/// <summary> /// Recuperar todos os BooksStock ordernado por um campo. /// </summary> /// <param name="fieldAscendingOrder">Informar o nome do campo</param> /// <returns>Todos os BooksStock por ordem ascendente</returns> public IQueryable <BookStock> GetAll(string fieldAscendingOrder) { var sortBy = SortBy.Ascending(fieldAscendingOrder); MongoCursor <BookStock> cursor = _booksStock.FindAll().SetSortOrder(sortBy); return(cursor.AsQueryable <BookStock>()); }
public IQueryable <T> GetAll(int page) { int skipsize = pagesize * (page - 1); MongoCursor <T> cursor = _collection.FindAll().SetSkip(skipsize).SetLimit(pagesize); return(cursor.AsQueryable <T>()); }
public IQueryable <TEntity> GetDbSet(Expression <Func <TEntity, bool> > queryExpression) { var query = Query <TEntity> .Where(queryExpression); MongoCursor <TEntity> cursor = _collection.Find(query); return(cursor.AsQueryable <TEntity>()); }
/// <summary> /// Get all records /// </summary> /// <returns></returns> public IQueryable <T> GetAll() { //var cursor = _database.GetCollection<dynamic>("expenses").FindAll(); //var list= cursor.ToList(); MongoCursor <T> cursor = _collection.FindAll(); return(cursor.AsQueryable <T>()); }
/// <summary> /// Filters the specified query. /// </summary> /// <param name="query">The query.</param> /// <returns></returns> public IQueryable <T> Filter(Dictionary <string, string> filterParams) { var queries = new List <IMongoQuery>(); if (filterParams.Count > 0) { foreach (var item in filterParams) { queries.Add(Query.EQ(item.Key, item.Value)); } } MongoCursor <T> cursor = collection.Find(Query.And(queries)); return(cursor.AsQueryable <T>()); }
/// <summary> /// 查询字符串,返回name 字段匹配keyWord的集合 /// </summary> /// <param name="pageIndex">当前页数</param> /// <param name="pageCount">总页数</param> /// <returns></returns> public List <BsonDocument> QuickSearch(int pageIndex, out int pageCount, string keyField, string keyWord) { MongoCursor <BsonDocument> hitQuery = GetBsonDocument(); IQueryable <BsonDocument> resultQuery = null; if (hitQuery != null) { resultQuery = hitQuery.AsQueryable(); if (!string.IsNullOrEmpty(keyWord)) { resultQuery = resultQuery.Where(c => c.Text(keyField).Trim().Contains(keyWord.Trim())); } return(Search(pageIndex, out pageCount, resultQuery)); } return(Search(pageIndex, out pageCount, hitQuery)); }
/// <summary> /// 查询字符串,返回name 字段匹配keyWord的集合 /// </summary> /// <param name="pageIndex">当前页数</param> /// <param name="pageCount">总页数</param> /// <returns></returns> public List <BsonDocument> QuickSearchForFile(int pageIndex, out int pageCount, string keyWord) { MongoCursor <BsonDocument> hitQuery = GetBsonDocument(); IQueryable <BsonDocument> resultQuery = null; if (hitQuery != null) { resultQuery = hitQuery.AsQueryable(); if (!string.IsNullOrEmpty(keyWord)) { resultQuery = resultQuery.Select(c => c.SourceBson("fileId")); resultQuery = resultQuery.Where(c => (c.Text("name") + c.Text("ext")).Trim().Contains(keyWord.Trim())); } return(Search(pageIndex, out pageCount, resultQuery)); } return(Search(pageIndex, out pageCount, hitQuery)); }
///<summary> /// Get all records ///</summary> ///<returns></returns> public IQueryable <T> GetAll() { MongoCursor <T> cursor = _collection.FindAll(); return(cursor.AsQueryable <T>()); }
/// <summary> /// Filters the with query. /// </summary> /// <param name="filterParams">The filter parameters.</param> /// <returns></returns> public IQueryable <T> FilterWithQuery(IMongoQuery filterParams) { MongoCursor <T> cursor = collection.Find(filterParams); return(cursor.AsQueryable <T>()); }