更新
Db.Update(entity) 会根据唯一键自动生成 WHERE 条件;如果你改用 fluent builder 却没有加任何条件,框架会抛异常,避免误写整张表。
更新单条记录
csharp
var affectedRows = Db.Update(entity).Execute();csharp
var affectedRows = await Db.Update(entity).ExecuteAsync();更新多条记录
csharp
var affectedRows = Db.UpdateMany(entities).Execute();带 where 条件的更新
csharp
var idsToUpdate = new[] { 1, 2, 3 };
var affectedRows = Db.Update(entity)
.WhereIn(i => i.Id, idsToUpdate)
.WhereEq(i => i.Name, "Tom")
.WhereLt(i => i.Age, 18)
.Execute();更新指定列
csharp
int affectedRows = Db.Update<EntityClass>()
.Set(i => i.Id, entity.Id)
.Set(i => i.Name, entity.Name)
.Execute();更新到指定表(单条)
csharp
int affectedRows = Db.Update(entity)
.To(table)
.Execute();所有更新类方法也都提供对应的 ExecuteAsync 版本。