FreeSql (X) updated data

FreeSql supports rich data update method, support single or batch updates, you can also return the updated value recorded in a specific database to perform.

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; }
}

Updating an Entity

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)

API

method return value parameter description
SetSource <this> T1 | IEnumerable Update data, set the updated entity
ToSql string Returns the SQL statement to be executed
ExecuteAffrows long The number of rows to execute SQL statements, the impact of return
ExecuteUpdated List<T1> Execute SQL statements, returns the updated record

Guess you like

Origin www.cnblogs.com/FreeSql/p/11531321.html