Update Fastest

This commit is contained in:
sunkaixuna 2021-11-18 01:06:52 +08:00
parent 9f2bae2a57
commit f8fa0d7708
2 changed files with 24 additions and 5 deletions

View File

@ -10,7 +10,7 @@ namespace SqlSugar
{ {
private SqlSugarProvider context; private SqlSugarProvider context;
private ISugarQueryable<T> queryable; private ISugarQueryable<T> queryable;
private string AsName { get; set; }
public FastestProvider(SqlSugarProvider sqlSugarProvider) public FastestProvider(SqlSugarProvider sqlSugarProvider)
{ {
this.context = sqlSugarProvider; this.context = sqlSugarProvider;
@ -28,7 +28,11 @@ namespace SqlSugar
var result = await buider.ExecuteBulkCopyAsync(dt); var result = await buider.ExecuteBulkCopyAsync(dt);
return result; return result;
} }
public IFastest<T> AS(string tableName)
{
this.AsName = tableName;
return this;
}
private DataTable ToDdateTable(List<T> datas) private DataTable ToDdateTable(List<T> datas)
{ {
DataTable tempDataTable = ReflectionInoCore<DataTable>.GetInstance().GetOrCreate("BulkCopyAsync" + typeof(T).FullName, () => queryable.Where(it => false).ToDataTable()); DataTable tempDataTable = ReflectionInoCore<DataTable>.GetInstance().GetOrCreate("BulkCopyAsync" + typeof(T).FullName, () => queryable.Where(it => false).ToDataTable());
@ -38,7 +42,7 @@ namespace SqlSugar
dt.Columns.Add(item.ColumnName, item.DataType); dt.Columns.Add(item.ColumnName, item.DataType);
} }
var entityInfo = this.context.EntityMaintenance.GetEntityInfo<T>(); var entityInfo = this.context.EntityMaintenance.GetEntityInfo<T>();
dt.TableName = queryable.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName); GetTableName(dt, entityInfo);
var columns = entityInfo.Columns; var columns = entityInfo.Columns;
foreach (var item in datas) foreach (var item in datas)
{ {
@ -62,6 +66,18 @@ namespace SqlSugar
return dt; return dt;
} }
private void GetTableName(DataTable dt, EntityInfo entityInfo)
{
if (this.AsName.HasValue())
{
dt.TableName = queryable.SqlBuilder.GetTranslationTableName(AsName);
}
else
{
dt.TableName = queryable.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
}
}
private object ValueConverter(EntityColumnInfo columnInfo,object value) private object ValueConverter(EntityColumnInfo columnInfo,object value)
{ {
if (value == null) if (value == null)
@ -72,5 +88,7 @@ namespace SqlSugar
} }
return value; return value;
} }
} }
} }

View File

@ -7,7 +7,8 @@ namespace SqlSugar
{ {
public interface IFastest<T> public interface IFastest<T>
{ {
IFastest<T> AS(string tableName);
int BulkCopy(List<T> datas); int BulkCopy(List<T> datas);
Task<int> BulkCopyAsync(List<T> datas); Task<int> BulkCopyAsync(List<T> datas);
} }
} }