首页 > 数据库技术 > 详细

FreeSql (十一)更新数据 Where

时间:2019-09-17 09:57:41      阅读:99      评论:0      收藏:0      [点我收藏+]
var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" + 
    "Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10";

IFreeSql fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionString(FreeSql.DataType.MySql, connstr)
    .UseAutoSyncStructure(true) //自动同步实体结构到数据库
    .Build();

[Table(Name = "tb_topic")]
class Topic {
    [Column(IsIdentity = true, IsPrimary = true)]
    public int Id { get; set; }
    public int Clicks { get; set; }
    public string Title { get; set; }
    public DateTime CreateTime { get; set; }
}

动态条件

Update<Topic>(object dywhere)

dywhere 支持

  • 主键值
  • new[] { 主键值1, 主键值2 }
  • Topic对象
  • new[] { Topic对象1, Topic对象2 }
  • new { id = 1 }

其他条件

除了顶上介绍的 dywhere 构造参数外,还支持 Where lambda/sql 方法

fsql.Update<>(Topic).Set(a => a.Title, "新标题").Where(a => a.Id == 1).ExecuteAffrows();
//UPDATE `tb_topic` SET Title = @title WHERE (Id = 1)

API

方法 返回值 参数 描述
Where <this> Lambda 表达式条件,仅支持实体基础成员(不包含导航对象)
Where <this> string, parms 原生sql语法条件,Where("id = ?id", new { id = 1 })
Where <this> T1 | IEnumerable 传入实体或集合,将其主键作为条件
WhereExists <this> ISelect 子查询是否存在
ToSql string 返回即将执行的SQL语句
ExecuteAffrows long 执行SQL语句,返回影响的行数
ExecuteUpdated List<T1> 执行SQL语句,返回更新后的记录

系列文章导航

FreeSql (十一)更新数据 Where

原文:https://www.cnblogs.com/FreeSql/p/11531324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!