• 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方法,没有则添加 ,有则修改

  • 相关阅读:
    杭州办理招行香港一卡通(两地一卡通)攻略
    Android高手进阶教程(二十)之Android与JavaScript方法相互调用!
    Android应用的自动升级、更新模块的实现
    18个最好的jQuery表格插件
    系统的本地策略不允许你采用交互式登录
    android中判断横屏或者竖屏并改变背景
    记录几个东东
    jsAnim学习
    win7下安装oracle10g出现未知错误,程序异常终止
    oracle创建用户并授权
  • 原文地址:https://www.cnblogs.com/wuzhenglong/p/6385311.html
Copyright © 2020-2023  润新知