diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs index 0c6e53e8c..fa822d948 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs @@ -737,10 +737,10 @@ namespace SqlSugar { return IntoTable(typeof(TableEntityType)); } - //public bool IntoTable(string[] columnNameList) - //{ - // return IntoTable(typeof(TableEntityType), columnNameList); - //} + public bool IntoTable(string TableName) + { + return IntoTable(typeof(TableEntityType), TableName); + } public bool IntoTable(Type TableEntityType) { var entityInfo=this.Context.EntityMaintenance.GetEntityInfo(TableEntityType); @@ -761,15 +761,27 @@ namespace SqlSugar 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; - //} + + public bool IntoTable(Type TableEntityType,string TableName) + { + //var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType); + var sqlInfo = this.ToSql(); + var name = this.SqlBuilder.GetTranslationTableName(TableName); + 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; + } + } } diff --git a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs index e906386ff..f3d0a27f0 100644 --- a/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs +++ b/Src/Asp.Net/SqlSugar/Interface/IQueryable.cs @@ -162,6 +162,8 @@ namespace SqlSugar bool IntoTable(); bool IntoTable(Type TableEntityType); + bool IntoTable(string tableName); + bool IntoTable(Type TableEntityType,string tableName); //bool IntoTable(Type TableEntityType, params string[] columnNameList); //bool IntoTable(params string[] columnNameList); List SetContext(Expression> whereExpression, ParameterT parameter);