Add IntoTable

This commit is contained in:
sunkaixuan
2023-02-22 09:36:02 +08:00
parent 7db3ab379d
commit cf55999f63
2 changed files with 44 additions and 0 deletions

View File

@@ -732,5 +732,44 @@ namespace SqlSugar
var result = ((this.Context.DbFirst) as DbFirstProvider).GetClassString(columns, ref className);
return result;
}
public bool IntoTable<TableEntityType>()
{
return IntoTable(typeof(TableEntityType));
}
//public bool IntoTable<TableEntityType>(string[] columnNameList)
//{
// return IntoTable(typeof(TableEntityType), columnNameList);
//}
public bool IntoTable(Type TableEntityType)
{
var entityInfo=this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
var sqlInfo=this.ToSql();
var name = this.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
var columns = "";
if (this.QueryBuilder.GetSelectValue != null && this.QueryBuilder.GetSelectValue.Contains(",")) ;
{
columns = "(";
foreach (var item in this.QueryBuilder.GetSelectValue.Split(','))
{
var column = Regex.Split(item,"AS").Last().Trim();
columns += $"{column},";
}
columns = columns.TrimEnd(',') + ")";
}
var sql= $" INSERT INTO {name} {columns} " + sqlInfo.Key;
this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
return true;
}
//public bool IntoTable(Type TableEntityType,params string [] columnNameList)
//{
// var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
// var columnsString =string.Join(",", columnNameList.Select(it => this.SqlBuilder.GetTranslationColumnName(it)));
// var sqlInfo = this.MergeTable().Select(columnsString).ToSql();
// var name = this.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
// var sql = $" INSERT INTO {name} ({columnsString}) " + sqlInfo.Key;
// this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
// return true;
//}
}
}

View File

@@ -159,6 +159,11 @@ namespace SqlSugar
List<TResult> ToList<TResult>(Expression<Func<T, TResult>> expression);
Task<List<TResult>> ToListAsync<TResult>(Expression<Func<T, TResult>> expression);
List<T> ToList();
bool IntoTable<TableEntityType>();
bool IntoTable(Type TableEntityType);
//bool IntoTable(Type TableEntityType, params string[] columnNameList);
//bool IntoTable<TableEntityType>(params string[] columnNameList);
List<T> SetContext<ParameterT>(Expression<Func<T, bool>> whereExpression, ParameterT parameter);
List<T> SetContext<ParameterT>(Expression<Func<T,object>> thisFiled, Expression<Func<object>> mappingFiled, ParameterT parameter);
List<T> SetContext<ParameterT>(Expression<Func<T, object>> thisFiled1, Expression<Func<object>> mappingFiled1, Expression<Func<T, object>> thisFiled2, Expression<Func<object>> mappingFiled2, ParameterT parameter);