update

2881099
2022-08-17 19:55:37 +08:00
parent 66101de027
commit 5b4c026d28
2 changed files with 24 additions and 0 deletions

@@ -18,6 +18,18 @@ fsql.InsertOrUpdate<T>()
.SetSource(items) //Data to be processed
//.IfExistsDoNothing() //If the data exists, do nothing (that means, insert the data if and only if the data does not exist)
.ExecuteAffrows();
//or..
var sql = fsql.Select<T2, T3>()
.ToSql((a, b) => new
{
id = a.id + 1,
name = "xxx"
}, FieldAliasOptions.AsProperty);
fsql.InsertOrUpdate<T>()
.SetSource(sql)
.ExecuteAffrows();
```
When the entity class has auto-increment properties, batch `InsertOrUpdate` can be split into two executions at most. Internally, FreeSql will calculate the data without self-increment and with self-increment, and execute the two commands of `insert into` and `merge into` mentioned above (using transaction execution).

@@ -18,6 +18,18 @@ fsql.InsertOrUpdate<T>()
.SetSource(items) //需要操作的数据
//.IfExistsDoNothing() //如果数据存在,啥事也不干(相当于只有不存在数据时才插入)
.ExecuteAffrows();
//或者..
var sql = fsql.Select<T2, T3>()
.ToSql((a, b) => new
{
id = a.id + 1,
name = "xxx"
}, FieldAliasOptions.AsProperty);
fsql.InsertOrUpdate<T>()
.SetSource(sql)
.ExecuteAffrows();
```
当实体类有自增属性时,批量 InsertOrUpdate 最多可被拆成两次执行,内部计算出未设置自增值、和有设置自增值的数据,分别执行 insert into 和 上面讲到的 merge into 两种命令(采用事务执行)。