public long Count <T>(DbQueryParams qParams) where T : class, new() { // First query part consists of search params with specified operator between List <IMongoQuery> queries = new List <IMongoQuery>(); foreach (var item in qParams.QueryParams) { queries.Add(Query.Matches(item.Key, new BsonRegularExpression(String.Format("(?:{0})", item.Value), "is"))); } var query = qParams.Operator == QueryOperator.AND ? Query.And(queries) : Query.Or(queries); return(mongoDb.GetCollection <T>(GetTypeName(typeof(T))).Count(query)); }
public List <T> Page <T>(DbQueryParams qParams) where T : class, new() { // First query part consists of search params with specified operator between List <IMongoQuery> queries = new List <IMongoQuery>(); foreach (var item in qParams.QueryParams) { queries.Add(Query.Matches(item.Key, new BsonRegularExpression(String.Format("(?:{0})", item.Value), "is"))); } var query = qParams.Operator == QueryOperator.AND ? Query.And(queries) : Query.Or(queries); MongoCursor <T> cursor = mongoDb.GetCollection <T>(GetTypeName(typeof(T))).Find(query); cursor.SetSkip(qParams.SkipRecords).SetLimit(qParams.Count); // Setting the Sort params if (qParams.SortParams != null && qParams.SortParams.Count > 0) { SortByBuilder sbb = new SortByBuilder(); foreach (KeyValuePair <string, bool> sortItem in qParams.SortParams) { if (sortItem.Value) { sbb.Ascending(sortItem.Key); } else { sbb.Descending(sortItem.Key); } } cursor.SetSortOrder(sbb); } return(cursor.ToList()); }
public List <User> GetPage(DbQueryParams qParams) { return(MongoSession.Page <User>(qParams)); }