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; }
}
Dynamic conditions
Update<Topic>(object dywhere)
dywhere support
- Primary key
- new [] {1 master key, the master key 2}
- Topic object
- new [] {Topic objects 1, Topic objects 2}
- new { id = 1 }
Other conditions
In addition to the top dywhere configuration parameters described, but also supports Where lambda / sql Method
fsql.Update<>(Topic).Set(a => a.Title, "新标题").Where(a => a.Id == 1).ExecuteAffrows();
//UPDATE `tb_topic` SET Title = @title WHERE (Id = 1)
API
method | return value | parameter | description |
---|---|---|---|
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 |
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 |