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; } }
fsql.Update<Topic>().SetSource(item).IgnoreColumns(a => a.Clicks).ExecuteAffrows(); //UPDATE `tb_topic` SET `Title` = ?p_0, `CreateTime` = ?p_1 WHERE (`Id` = 1) fsql.Update<Topic>().SetSource(item).IgnoreColumns(a => new { a.Clicks, a.CreateTime }).ExecuteAffrows(); //UPDATE `tb_topic` SET `Title` = ?p_0 WHERE (`Id` = 1)
方法 | 返回值 | 参数 | 描述 |
---|---|---|---|
SetSource | <this> | T1 | IEnumerable
|
更新数据,设置更新的实体 |
IgnoreColumns | <this> | Lambda | 忽略的列 |
Set | <this> | Lambda, value | 设置列的新值,Set(a => a.Name, "newvalue") |
Set | <this> | Lambda | 设置列的的新值为基础上增长,Set(a => a.Clicks + 1),至关于 clicks=clicks+1; |
SetRaw | <this> | string, parms | 设置值,自定义SQL语法,SetRaw("title = ?title", new { title = "newtitle" }) |
Where | <this> | Lambda | 表达式条件,仅支持实体基础成员(不包含导航对象) |
Where | <this> | string, parms | 原生sql语法条件,Where("id = ?id", new { id = 1 }) |
Where | <this> | T1 | IEnumerable
|
传入实体或集合,将其主键做为条件 |
WhereExists | <this> | ISelect | 子查询是否存在 |
WithTransaction | <this> | DbTransaction | 设置事务对象 |
ToSql | string | 返回即将执行的SQL语句 | |
ExecuteAffrows | long | 执行SQL语句,返回影响的行数 | |
ExecuteUpdated | List<T1> | 执行SQL语句,返回更新后的记录 |
(一)入门html
(二)自动迁移实体sql
(三)实体特性数据库
(五)插入数据ui
(六)批量插入数据this
(七)插入数据时忽略列code
(八)插入数据时指定列htm
(九)删除数据对象
(十)更新数据blog
(十三)更新数据时忽略列