Пример #1
0
        public DefaultResult <List <Log_Info_House> > Mongodb_House_Get()
        {
            WCFMongoClient <Log_Info_House> client = new WCFMongoClient <Log_Info_House>(Startup.MongodbUrl);

            //排序方式
            var orderby = new List <CommonOrderModel>()
            {
                new CommonOrderModel()
                {
                    Name = "AddTime", Order = 1
                }
            };
            //wcf查询过滤条件
            var filterList = new List <CommonFilterModel>();

            //增加过滤条件
            filterList.Add(new CommonFilterModel("userid", "=", "58989"));
            filterList.Add(new CommonFilterModel("AddTime", ">", DateTime.Now.AddMinutes(-10).ToString()));
            var res = client.GetListByQuery(1, 1, filterList, orderby);

            //Expression<Func<Log_Info_House, bool>> predicate = u => u.userid == 58989;
            //Func<Sort<Log_Info_House>, Sort<Log_Info_House>> sort = b => b.Desc(c => c.AddTime);
            //var res = client.mongoRepository.ToList<Log_Info_House>(predicate, sort, 1);

            return(res);
        }
Пример #2
0
        public DefaultResult <List <Logs> > mongodbGet()
        //public List<Logs> mongodbGet()
        {
            WCFMongoClient <Logs> client = new WCFMongoClient <Logs>(Startup.MongodbUrl);

            //排序方式
            var orderby = new List <CommonOrderModel>()
            {
                new CommonOrderModel()
                {
                    Name = "CreateTime", Order = 1
                }
            };
            //wcf查询过滤条件
            var filterList = new List <CommonFilterModel>();

            //增加过滤条件
            filterList.Add(new CommonFilterModel("UserId", "=", "58988"));
            var res = client.GetListByQuery(1, 1, filterList, orderby);

            //Expression<Func<Logs, bool>> predicate = u => u.UserId == 58988;
            //Func<Sort<Logs>, Sort<Logs>> sort = b => b.Desc(c => c.CreateTime);
            //var res = client.mongoRepository.ToList<Logs>(predicate, sort, 1);

            return(res);

            #region 测试
            //var res = client.mongoRepository.PageList<Logs>(u => u.UserId == 58988, b => b.Desc(c => c.CreateTime), 1, 1);
            //GetListByQuery
            //var res = client.GetModel(filterList, orderby);
            //var res = client.GetModelByID("ed13c7e7b4cd478ca0fe37a7a709d6ec");
            //var rep = client.mongoRepository;
            //IMongoCollection<T> collection2 = GetCollection<T>(database, collection);
            //int totalCount = (int)IMongoCollectionExtensions.CountDocuments(collection2, predicate);
            //IFindFluent<T, T> findFluent = collection2.Find(predicate);
            //if (sort != null)
            //{
            //    findFluent = findFluent.Sort(sort.GetSortDefinition());
            //}
            //findFluent = findFluent.Skip((pageIndex - 1) * pageSize).Limit(pageSize);
            //List<TResult> items = findFluent.Project(selector).ToList();

            //return  rep.Get<Logs>(w => w.UserId == 58988,b=>b.Desc(c=>c.CreateTime));


            ////无任何转换查询

            //Expression<Func<Logs, bool>> predicate = u => u.UserId == 58988;
            //var _mongoClient = new MongoClient(Startup.MongodbUrl);
            //IMongoCollection<Logs> collection2 = _mongoClient.GetDatabase("test").GetCollection<Logs>("testlogs");
            //int totalCount = (int)IMongoCollectionExtensions.CountDocuments(collection2, predicate);
            //IFindFluent<Logs, Logs> findFluent = collection2.Find(predicate);
            //Func<Sort<Logs>, Sort<Logs>> sort = b => b.Desc(c => c.CreateTime);
            //if (sort != null)
            //{
            //    findFluent = findFluent.Sort(sort.GetSortDefinition());
            //}
            //findFluent = findFluent.Skip((1 - 1) * 1).Limit(1);
            //List<Logs> items = findFluent.Project((Logs a) => a).ToList();

            //return items;
            #endregion 测试
        }