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
(十三)更新數據時忽略列