mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
update mysql bulkcopy
This commit is contained in:
parent
f9491cbccd
commit
5d31ca0e6a
60
Src/Asp.Net/MySqlTest/Demo/DemoO_Fastest.cs
Normal file
60
Src/Asp.Net/MySqlTest/Demo/DemoO_Fastest.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using OrmTest;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest
|
||||||
|
{
|
||||||
|
public class TestFAST111
|
||||||
|
{
|
||||||
|
|
||||||
|
public int Sex { get; set; }
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true)]
|
||||||
|
public string Id { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsNullable = true)]
|
||||||
|
public long X { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsNullable = true,IsJson =true,ColumnDataType ="varchar(500)")]
|
||||||
|
public string [] json { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DemoO_Fastest
|
||||||
|
{
|
||||||
|
public static void Init()
|
||||||
|
{
|
||||||
|
Console.WriteLine("");
|
||||||
|
Console.WriteLine("#### Insertable Start ####");
|
||||||
|
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = DbType.MySql,
|
||||||
|
ConnectionString = Config.ConnectionString,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
AopEvents = new AopEvents
|
||||||
|
{
|
||||||
|
OnLogExecuting = (sql, p) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine(sql);
|
||||||
|
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
db.CodeFirst.InitTables<TestFAST111>();
|
||||||
|
db.Fastest<TestFAST111>().BulkCopy(new List<TestFAST111>() {
|
||||||
|
new TestFAST111(){ Date=DateTime.Now, Id=Guid.NewGuid()+"", Sex=1 , X=111,json=new string[]{ "x"} }
|
||||||
|
});
|
||||||
|
var data = new List<TestFAST111>() {
|
||||||
|
new TestFAST111(){ Date=DateTime.Now, Id=Guid.NewGuid()+"", Sex=2 , X=112,json=new string[]{ "x"} }
|
||||||
|
};
|
||||||
|
//db.Updateable(data).ExecuteCommand();
|
||||||
|
db.Fastest<TestFAST111>().BulkUpdate(data);
|
||||||
|
var x = db.Queryable<TestFAST111>().ToList();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -65,6 +65,7 @@
|
|||||||
<Compile Include="Demo\DemoF_Utilities.cs" />
|
<Compile Include="Demo\DemoF_Utilities.cs" />
|
||||||
<Compile Include="Demo\DemoG_SimpleClient.cs" />
|
<Compile Include="Demo\DemoG_SimpleClient.cs" />
|
||||||
<Compile Include="Demo\DemoN_SplitTable.cs" />
|
<Compile Include="Demo\DemoN_SplitTable.cs" />
|
||||||
|
<Compile Include="Demo\DemoO_Fastest.cs" />
|
||||||
<Compile Include="Models\AttributeTable.cs" />
|
<Compile Include="Models\AttributeTable.cs" />
|
||||||
<Compile Include="Models\CarType.cs" />
|
<Compile Include="Models\CarType.cs" />
|
||||||
<Compile Include="Models\Custom.cs" />
|
<Compile Include="Models\Custom.cs" />
|
||||||
|
@ -164,14 +164,18 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
colum = table.Columns[i];
|
colum = table.Columns[i];
|
||||||
if (i != 0) sb.Append(",");
|
if (i != 0) sb.Append(",");
|
||||||
if (colum.DataType == typeof(string) &&( row[colum].ToString().Contains(",") || row[colum].ToString().Contains("\r")||row[colum].ToString().Contains("\"")))
|
if (colum.DataType == typeof(string) && (row[colum].ToString().Contains(",") || row[colum].ToString().Contains("\r") || row[colum].ToString().Contains("\"")))
|
||||||
{
|
{
|
||||||
sb.Append("\"" + row[colum].ToString().Replace("\"", "\"\"") + "\"");
|
sb.Append("\"" + row[colum].ToString().Replace("\"", "\"\"") + "\"");
|
||||||
}
|
}
|
||||||
else if (colum.DataType == typeof(bool))
|
else if (colum.DataType == typeof(bool))
|
||||||
{
|
{
|
||||||
sb.Append(row[colum].ObjToBool() ? 1 : 0);
|
sb.Append(row[colum].ObjToBool() ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
else if (colum.DataType == UtilConstants.DateType)
|
||||||
|
{
|
||||||
|
sb.Append(row[colum].ObjToDate().ToString("yyyy-MM-dd HH:mm:ss.fff"));
|
||||||
|
}
|
||||||
else sb.Append(row[colum].ToString());
|
else sb.Append(row[colum].ToString());
|
||||||
}
|
}
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user