public async Task UpdateOne() { UserRepAsync userRep = new UserRepAsync(); await userRep.UpdateOneAsync(x => x.ID == 4, UserRepAsync.Update.Set(nameof(User.CreateTime), DateTime.Now)); //UserRepAsync.Update.Set("_id", 1); //UserRepAsync.Update.Set(x => x.ID, 1); await userRep.UpdateOneAsync(x => x.Name == "bb", UserRepAsync.Update.Set(nameof(User.CreateTime), DateTime.Now)); long id = await userRep.CreateIncIDAsync(); var update = UserRepAsync.Update.Set(nameof(User.Name), "xyz"); update = update.SetOnInsert(x => x.ID, id).SetOnInsert(x => x.CreateTime, DateTime.Now); await userRep.UpdateOneAsync(x => x.Name == "abc", update, true); var res = await userRep.UpdateOneAsync(x => x.Name == "xyz", update, true, WriteConcern.Acknowledged); Assert.AreEqual(res.IsAcknowledged, true); }
public async Task UpdateOne_updateEntity() { User user = new User(); UserRepAsync userRep = new UserRepAsync(); //user = await userRep.GetAsync(x => x.Name == "xx"); user.Age += 1; user.CreateTime = DateTime.Now; user.Name = "axxxx"; await userRep.UpdateOneAsync(x => x.Name == "axxxx", user, true); //user = await userRep.Get(14); //user.Age += 1; //user.CreateTime = DateTime.Now; //user.Name = "gg"; //await userRep.UpdateOne(user, false); }