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; }
}
Save entity, ignore some columns
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)
API
SetSource |
<this> |
T1 | IEnumerable
|
Update data, set the updated entity |
IgnoreColumns |
<this> |
Lambda |
Ignore column |
Set |
<this> |
Lambda, value |
Setting a new value column, Set (a => a.Name, "newvalue") |
Set |
<this> |
Lambda |
Setting a new value of the column on the basis of the increase, Set (a => a.Clicks + 1), corresponding to clicks = clicks + 1; |
SetRaw |
<this> |
string, parms |
Set value, a custom SQL syntax, SetRaw ( "title =? Title", new {title = "newtitle"}) |
Where |
<this> |
Lambda |
Expression conditions, only the physical infrastructure to support members (not contain navigation objects) |
Where |
<this> |
string, parms |
Sql syntax native conditions, Where ( "id =? Id", new {id = 1}) |
Where |
<this> |
T1 | IEnumerable
|
Incoming entity or set as a condition to its primary key |
WhereExists |
<this> |
ISelect |
The existence of sub-query |
WithTransaction |
<this> |
DbTransaction |
Set transaction object |
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 |