mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-04 15:30:53 +08:00
update
@@ -17,13 +17,13 @@ class Topic {
|
||||
}
|
||||
|
||||
var items = new List<Topic>();
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
```
|
||||
|
||||
## 1. Single Insert
|
||||
|
||||
```csharp
|
||||
var t1 = fsql.Insert(items.First()).ExecuteAffrows();
|
||||
var t1 = fsql.Insert(items[0]).ExecuteAffrows();
|
||||
//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`)
|
||||
//VALUES(@Clicks0, @Title0, @CreateTime0)
|
||||
```
|
||||
@@ -32,16 +32,16 @@ If the table has auto-increment columns, `id` will be returned after inserting d
|
||||
|
||||
Method 1: (Original)
|
||||
```csharp
|
||||
long id = fsql.Insert(blog).ExecuteIdentity();
|
||||
blog.Id = id;
|
||||
long id = fsql.Insert(items[0]).ExecuteIdentity();
|
||||
items[0].Id = id;
|
||||
```
|
||||
|
||||
Method 2: (depends on FreeSql.Repository)
|
||||
```csharp
|
||||
var repo = fsql.GetRepository<Blog>();
|
||||
repo.Insert(blog);
|
||||
var repo = fsql.GetRepository<Topic>();
|
||||
repo.Insert(items[0]);
|
||||
```
|
||||
> In the internal implementation, after inserting the data, the self-incremental value will be assigned to `blog.Id`
|
||||
> In the internal implementation, after inserting the data, the self-incremental value will be assigned to `items[0].Id` (support batch insert backfill)
|
||||
|
||||
## 2. Batch Insert
|
||||
|
||||
|
||||
23
添加.md
23
添加.md
@@ -17,31 +17,34 @@ class Topic {
|
||||
}
|
||||
|
||||
var items = new List<Topic>();
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Id = a + 1, Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
for (var a = 0; a < 10; a++) items.Add(new Topic { Title = $"newtitle{a}", Clicks = a * 100 });
|
||||
```
|
||||
|
||||
## 1、单条插入
|
||||
|
||||
```csharp
|
||||
var t1 = fsql.Insert(items.First()).ExecuteAffrows();
|
||||
var t1 = fsql.Insert(items[0]).ExecuteAffrows();
|
||||
//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`)
|
||||
//VALUES(@Clicks0, @Title0, @CreateTime0)
|
||||
//VALUES(?Clicks0, ?Title0, ?CreateTime0)
|
||||
```
|
||||
|
||||
如果表有自增列,插入数据后应该要返回 id。
|
||||
|
||||
方法1:(原始)
|
||||
方法 1:(原始)
|
||||
|
||||
```csharp
|
||||
long id = fsql.Insert(blog).ExecuteIdentity();
|
||||
blog.Id = id;
|
||||
long id = fsql.Insert(items[0]).ExecuteIdentity();
|
||||
items[0].Id = id;
|
||||
```
|
||||
|
||||
方法2:(依赖 FreeSql.Repository)
|
||||
方法 2:(依赖 FreeSql.Repository)
|
||||
|
||||
```csharp
|
||||
var repo = fsql.GetRepository<Blog>();
|
||||
repo.Insert(blog);
|
||||
var repo = fsql.GetRepository<Topic>();
|
||||
repo.Insert(items[0]);
|
||||
```
|
||||
> 内部会将插入后的自增值填充给 blog.Id
|
||||
|
||||
> 内部会将插入后的自增值填充给 items[0].Id (支持批量插入回填)
|
||||
|
||||
## 2、批量插入
|
||||
|
||||
|
||||
Reference in New Issue
Block a user