Commit 784c631b by 泽锋 李

fix

parent 7dd0b81c
...@@ -211,12 +211,13 @@ namespace AutoTurnOver.DB.Base ...@@ -211,12 +211,13 @@ namespace AutoTurnOver.DB.Base
/// <param name="dt">源数据</param> /// <param name="dt">源数据</param>
public static int BatchInsert<T>(this MySqlConnection conn,IList<T> list, string tableName) public static int BatchInsert<T>(this MySqlConnection conn,IList<T> list, string tableName)
{ {
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start();//开始计时
var connectionString = conn.ConnectionString; var connectionString = conn.ConnectionString;
var sourceTable = DataTableExtensions.ToDataTable<T>(list); var sourceTable = DataTableExtensions.ToDataTable<T>(list);
int insertCount = 0; int insertCount = 0;
int pageIndex = 1; int pageIndex = 1;
int pageSize = 500000; int pageSize = 500000;
while (true) while (true)
{ {
DataTable table = DtSelectTop((pageIndex - 1) * pageSize, pageIndex * pageSize, sourceTable); DataTable table = DtSelectTop((pageIndex - 1) * pageSize, pageIndex * pageSize, sourceTable);
...@@ -258,6 +259,7 @@ namespace AutoTurnOver.DB.Base ...@@ -258,6 +259,7 @@ namespace AutoTurnOver.DB.Base
} }
File.Delete(tmpPath); File.Delete(tmpPath);
} }
Console.WriteLine($" 写入 {list.Count} 条数据,耗时 {watch.ElapsedMilliseconds} 毫秒 ");
return insertCount; return insertCount;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment