update mysql bulkcopy

This commit is contained in:
sunkaixuna 2022-01-22 13:43:16 +08:00
parent f9491cbccd
commit 5d31ca0e6a
3 changed files with 67 additions and 2 deletions

View 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();
}
}
}

View File

@ -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" />

View File

@ -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();