public async Task FindOneAndUpdate() { User user; UserRepAsync userRep = new UserRepAsync(); user = await userRep.GetAsync(2); user.Age += 1; user.CreateTime = DateTime.Now; //user.Desc = "ggggsdgsa"; user = await userRep.FindOneAndUpdateAsync(filterExp : x => x.ID == user.ID, updateEntity : user, isUpsert : false); }
public async Task Get() { UserRepAsync userRep = new UserRepAsync(); List <User> list = await userRep.GetListAsync(limit : 1); User user = list.First(); long id = user.ID; user = await userRep.GetAsync(user.ID); Assert.AreEqual(user.ID, id); user = await userRep.GetAsync(x => x.Name == "aa"); Assert.AreNotEqual(user, null); user = await userRep.GetAsync(x => x.Name == "aa", x => new { x.Name }); Assert.AreNotEqual(user, null); user = await userRep.GetAsync(x => x.Name == "aa", x => new { x.CreateTime }); Assert.AreNotEqual(user, null); user = await userRep.GetAsync(x => x.Name == "aa" && x.CreateTime > DateTime.Parse("2015/10/20")); Assert.AreNotEqual(user, null); Builders <User> .Filter.Eq("Name", "aa"); var filter = UserRepAsync.Filter.Eq(x => x.Name, "aa") & UserRepAsync.Filter.Eq(x => x.ID, 123); UserRepAsync.Sort.Descending("_id"); user = await userRep.GetAsync(Builders <User> .Filter.Eq("Name", "aa"), null, Builders <User> .Sort.Descending("_id")); Assert.AreNotEqual(user, null); user = await userRep.GetAsync(filter : Builders <User> .Filter.Eq("Name", "aa"), projection : Builders <User> .Projection.Include(x => x.Name)); Assert.AreNotEqual(user, null); }