ServiceStack.OrmLite 笔记5 改

修改

db.Update(new Person { Id = 1, FirstName = "Jimi", LastName = "Hendrix", Age = 27});
// sql:UPDATE "Person" SET "FirstName" = 'Jimi',"LastName" = 'Hendrix',"Age" = 27 WHERE "Id" = 1

db.Update(new Person { Id = 1, FirstName = "JJ" }, p => p.LastName == "Hendrix");
// UPDATE "Person" SET "Id" = 1,"FirstName" = 'JJ',"LastName" = NULL,"Age" = NULL WHERE ("LastName" = 'Hendrix')

//部分更新
db.Update(new { FirstName = "JJ" }, p => p.LastName == "Hendrix");
db.UpdateNonDefaults(new Person { FirstName = "JJ" }, p => p.LastName == "Hendrix");
//UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
//UPDATE "Person" SET "FirstName" = 'JJ'

db.UpdateOnly(new Person { FirstName = "JJ", Age = 12 },
onlyFields: p => new { p.FirstName, p.Age });
//UPDATE "Person" SET "FirstName" = 'JJ', "Age" = 12

db.UpdateOnly(new Person { FirstName = "JJ" },
onlyFields: p => p.FirstName,
where: p => p.LastName == "Hendrix");
//UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')

db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" },
onlyFields: q => q.Update(p => p.FirstName));
//UPDATE "Person" SET "FirstName" = 'JJ'

db.UpdateOnly(new Person { FirstName = "JJ" },
onlyFields: q => q.Update(p => p.FirstName).Where(x => x.LastName == "Jimi"));
//UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Jimi')

db.Update(set: "FirstName = {0}".Params("JJ"),
where: "LastName = {0}".Params("Hendrix"));

db.Update(table: "Person", set: "FirstName = {0}".Params("JJ"),
where: "LastName = {0}".Params("Hendrix"));
//UPDATE "Person" SET FirstName = 'JJ' WHERE LastName = 'Hendrix'

//先获取 再更新
var updatedRow = db.SingleById(rowId);
db.Update(updatedRow);
// save方法,没有则添加 ,有则修改
Save and SaveAll will Insert if no record with Id exists, otherwise it Updates

上一篇:XCode中#pragma的使用


下一篇:Nagios3完整配置文档