diff --git a/Insert-Data.md b/Insert-Data.md index b6aa396..06880e2 100644 --- a/Insert-Data.md +++ b/Insert-Data.md @@ -17,13 +17,13 @@ class Topic { } var items = new List(); -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(); -repo.Insert(blog); +var repo = fsql.GetRepository(); +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 diff --git a/添加.md b/添加.md index e7f491f..26909bb 100644 --- a/添加.md +++ b/添加.md @@ -17,31 +17,34 @@ class Topic { } var items = new List(); -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(); -//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`) -//VALUES(@Clicks0, @Title0, @CreateTime0) +var t1 = fsql.Insert(items[0]).ExecuteAffrows(); +//INSERT INTO `Topic`(`Clicks`, `Title`, `CreateTime`) +//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(); -repo.Insert(blog); +var repo = fsql.GetRepository(); +repo.Insert(items[0]); ``` -> 内部会将插入后的自增值填充给 blog.Id + +> 内部会将插入后的自增值填充给 items[0].Id (支持批量插入回填) ## 2、批量插入