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

你可能感兴趣的:(ServiceStack.OrmLite 笔记5 改)