public async Task UpdateOne() { UserRepAsync userRep = new UserRepAsync(); await userRep.UpdateOneAsync(x => x.ID == 4, UserRepAsync.Update.Set(nameof(User.CreateTime), DateTime.Now)); await userRep.UpdateOneAsync(x => x.Name == "bb", UserRepAsync.Update.Set(nameof(User.CreateTime), DateTime.Now)); //获取当前自增ID 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.ID == 1); user.Age += 1; user.CreateTime = DateTime.Now; user.Name = "axxxx"; await userRep.UpdateOneAsync(x => x.Name == "axxxx", user, false); //根据条件查询,然后修改 user = await userRep.GetAsync(x => x.Name == "axxxx"); user.Age = 12; await userRep.UpdateOneAsync(x => x.ID == user.ID, user, true); }