FreeSql支持丰富的更新数据方法,支持单条或批量更新,在特定的数据库执行还能够返回更新后的记录值。html
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; } }
var item = new Topic { Id = 1, Title = "newtitle" }; fsql.Update<Topic>().SetSource(item).ExecuteAffrows(); //UPDATE `tb_topic` SET `Clicks` = ?p_0, `Title` = ?p_1, `CreateTime` = ?p_2 WHERE (`Id` = 1)
方法 | 返回值 | 参数 | 描述 |
---|---|---|---|
SetSource | <this> | T1 | IEnumerable
|
更新数据,设置更新的实体 |
ToSql | string | 返回即将执行的SQL语句 | |
ExecuteAffrows | long | 执行SQL语句,返回影响的行数 | |
ExecuteUpdated | List<T1> | 执行SQL语句,返回更新后的记录 |
(一)入门sql
(二)自动迁移实体数据库
(三)实体特性api
(五)插入数据this
(六)批量插入数据code
(七)插入数据时忽略列htm
(八)插入数据时指定列blog
(九)删除数据事务
(十)更新数据