mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update db.Fastest
This commit is contained in:
parent
7050a293b2
commit
d3b8ecaf4d
46
Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastBuilder.cs
Normal file
46
Src/Asp.Net/SqlSugar/Abstract/FastestProvider/FastBuilder.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class FastBuilder
|
||||
{
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
|
||||
public string UpdateSql { get; set; } = @"UPDATE TM
|
||||
SET {0}
|
||||
FROM {1} TM
|
||||
INNER JOIN {2} TE ON {3} ";
|
||||
|
||||
|
||||
public void CloseDb()
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
|
||||
{
|
||||
Check.ArgumentNullException(!updateColumns.Any(), "update columns count is 0");
|
||||
Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
|
||||
var sets = string.Join(",", updateColumns.Select(it => $"TM.{it}=TE.{it}"));
|
||||
var wheres = string.Join(",", whereColumns.Select(it => $"TM.{it}=TE.{it}"));
|
||||
string sql = string.Format(UpdateSql, sets, tableName, tempName, wheres);
|
||||
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
||||
}
|
||||
|
||||
public async Task CreateTempAsync<T>(DataTable dt) where T : class, new()
|
||||
{
|
||||
await this.Context.UnionAll(
|
||||
this.Context.Queryable<T>().Where(it => false).AS(dt.TableName),
|
||||
this.Context.Queryable<T>().Where(it => false).AS(dt.TableName)).Select("top 1 * into #temp").ToListAsync();
|
||||
dt.TableName = "#temp";
|
||||
}
|
||||
}
|
||||
}
|
@ -94,7 +94,7 @@ namespace SqlSugar
|
||||
private async Task<int> _BulkCopy(List<T> datas)
|
||||
{
|
||||
DataTable dt = ToDdateTable(datas);
|
||||
IFastBuilder buider = new SqlServerFastBuilder();
|
||||
IFastBuilder buider =GetBuider();
|
||||
buider.Context = context;
|
||||
var result = await buider.ExecuteBulkCopyAsync(dt);
|
||||
return result;
|
||||
|
@ -8,16 +8,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class SqlServerFastBuilder: IFastBuilder
|
||||
|
||||
public class SqlServerFastBuilder:FastBuilder,IFastBuilder
|
||||
{
|
||||
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
|
||||
public string UpdateSql { get; set; } = @"UPDATE TM
|
||||
SET {0}
|
||||
FROM {1} TM
|
||||
INNER JOIN {2} TE ON {3} ";
|
||||
|
||||
public async Task<int> ExecuteBulkCopyAsync(DataTable dt)
|
||||
{
|
||||
|
||||
@ -52,30 +45,6 @@ namespace SqlSugar
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
public void CloseDb()
|
||||
{
|
||||
if (this.Context.CurrentConnectionConfig.IsAutoCloseConnection && this.Context.Ado.Transaction == null)
|
||||
{
|
||||
this.Context.Ado.Connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> UpdateByTempAsync(string tableName, string tempName, string[] updateColumns, string[] whereColumns)
|
||||
{
|
||||
Check.ArgumentNullException(!updateColumns.Any(),"update columns count is 0");
|
||||
Check.ArgumentNullException(!whereColumns.Any(), "where columns count is 0");
|
||||
var sets = string.Join(",", updateColumns.Select(it=>$"TM.{it}=TE.{it}"));
|
||||
var wheres = string.Join(",", whereColumns.Select(it => $"TM.{it}=TE.{it}"));
|
||||
string sql = string.Format(UpdateSql,sets, tableName,tempName, wheres);
|
||||
return await this.Context.Ado.ExecuteCommandAsync(sql);
|
||||
}
|
||||
|
||||
public async Task CreateTempAsync<T>(DataTable dt) where T :class,new()
|
||||
{
|
||||
await this.Context.UnionAll(
|
||||
this.Context.Queryable<T>().Where(it => false).AS(dt.TableName),
|
||||
this.Context.Queryable<T>().Where(it => false).AS(dt.TableName)).Select("top 1 * into #temp").ToListAsync();
|
||||
dt.TableName = "#temp";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +88,10 @@
|
||||
<Compile Include="Abstract\DeleteProvider\SplitTableDeleteProvider.cs" />
|
||||
<Compile Include="Abstract\EntityMaintenance\EntityMaintenance.cs" />
|
||||
<Compile Include="Abstract\ExpressionableProvider\Expressionable.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\FastBuilder.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\FastestProvider.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\_Private.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\_Setting.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\Private.cs" />
|
||||
<Compile Include="Abstract\FastestProvider\Setting.cs" />
|
||||
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
|
||||
<Compile Include="Interface\IFastBuilder.cs" />
|
||||
<Compile Include="Interface\IFastest.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user