ServiceStack.OrmLite 笔记4 删

时间:2021-08-22 22:47:00

删除

db.DeleteAll();

//各种姿势
db.Delete(p => p.Age == 27);//
db.Delete(q => q.Where(p => p.Age == 27));// 同上
db.Delete(where: "Age = {0}".Params(27));
db.Delete(table: "Person", where: "Age = {0}".Params(27));
// sql:DELETE FROM "Person" WHERE Age = 27

//加个保护 更安全
public class Poco
{
...
public ulong RowVersion { get; set; }
}
var updatedRow = db.SingleById(rowId); // fresh version
db.DeleteById(id:updatedRow.Id, rowversion:updatedRow.RowVersion)