mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-20 02:29:39 +08:00
Synchronization code
This commit is contained in:
@@ -752,43 +752,16 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public int IntoTable(Type TableEntityType)
|
public int IntoTable(Type TableEntityType)
|
||||||
{
|
{
|
||||||
var entityInfo=this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
|
||||||
var sqlInfo=this.ToSql();
|
|
||||||
var name = this.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
|
var name = this.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
|
||||||
var columns = "";
|
return IntoTable(TableEntityType, name);
|
||||||
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;
|
|
||||||
return this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int IntoTable(Type TableEntityType,string TableName)
|
public int IntoTable(Type TableEntityType,string TableName)
|
||||||
{
|
{
|
||||||
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
|
KeyValuePair<string, List<SugarParameter>> sqlInfo;
|
||||||
var sqlInfo = this.ToSql();
|
string sql;
|
||||||
var name = this.SqlBuilder.GetTranslationTableName(TableName);
|
OutIntoTableSql(TableName, out sqlInfo, out sql, TableEntityType);
|
||||||
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;
|
|
||||||
return this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
|
return this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -674,5 +674,29 @@ ParameterT parameter)
|
|||||||
var list = await this.ToListAsync();
|
var list = await this.ToListAsync();
|
||||||
return GetChildList(parentIdExpression, pk, list, primaryKeyValue, isContainOneself);
|
return GetChildList(parentIdExpression, pk, list, primaryKeyValue, isContainOneself);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Task<int> IntoTableAsync<TableEntityType>(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return IntoTableAsync(typeof(TableEntityType), cancellationToken);
|
||||||
|
}
|
||||||
|
public Task<int> IntoTableAsync<TableEntityType>(string TableName, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return IntoTableAsync(typeof(TableEntityType), TableName, cancellationToken );
|
||||||
|
}
|
||||||
|
public Task<int> IntoTableAsync(Type TableEntityType, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
|
||||||
|
var name = this.SqlBuilder.GetTranslationTableName(entityInfo.DbTableName);
|
||||||
|
return IntoTableAsync(TableEntityType, name, cancellationToken);
|
||||||
|
}
|
||||||
|
public async Task<int> IntoTableAsync(Type TableEntityType, string TableName, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
this.Context.Ado.CancellationToken= cancellationToken;
|
||||||
|
KeyValuePair<string, List<SugarParameter>> sqlInfo;
|
||||||
|
string sql;
|
||||||
|
OutIntoTableSql(TableName, out sqlInfo, out sql,TableEntityType);
|
||||||
|
return await this.Context.Ado.ExecuteCommandAsync(sql, sqlInfo.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1187,6 +1187,48 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Other
|
#region Other
|
||||||
|
|
||||||
|
private void OutIntoTableSql(string TableName, out KeyValuePair<string, List<SugarParameter>> sqlInfo, out string sql,Type tableInfo)
|
||||||
|
{
|
||||||
|
var columnList = this.Context.EntityMaintenance.GetEntityInfo(tableInfo).Columns;
|
||||||
|
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
|
||||||
|
sqlInfo = this.ToSql();
|
||||||
|
var name = this.SqlBuilder.GetTranslationTableName(TableName);
|
||||||
|
var columns = "";
|
||||||
|
sql = "";
|
||||||
|
var isSqlFunc = this.QueryBuilder.GetSelectValue?.Contains(")") == true && this.QueryBuilder.SelectValue is Expression;
|
||||||
|
if (isSqlFunc)
|
||||||
|
{
|
||||||
|
columns = "(";
|
||||||
|
foreach (var item in ExpressionTool.GetNewExpressionItemList((Expression)this.QueryBuilder.SelectValue))
|
||||||
|
{
|
||||||
|
var column = item.Key;
|
||||||
|
var columnInfo = columnList.FirstOrDefault(it => it.PropertyName == item.Key);
|
||||||
|
if (columnInfo != null)
|
||||||
|
{
|
||||||
|
column =this.SqlBuilder.GetTranslationColumnName(columnInfo.DbColumnName);
|
||||||
|
}
|
||||||
|
columns += $"{column},";
|
||||||
|
}
|
||||||
|
columns = columns.TrimEnd(',') + ")";
|
||||||
|
sql = $" INSERT INTO {name} {columns} " + sqlInfo.Key;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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(',') + ")";
|
||||||
|
}
|
||||||
|
sql = $" INSERT INTO {name} {columns} " + sqlInfo.Key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string GetTableName(EntityInfo entity, string tableName)
|
private string GetTableName(EntityInfo entity, string tableName)
|
||||||
{
|
{
|
||||||
var oldTableName = tableName;
|
var oldTableName = tableName;
|
||||||
|
@@ -182,6 +182,12 @@ namespace SqlSugar
|
|||||||
int IntoTable(Type TableEntityType);
|
int IntoTable(Type TableEntityType);
|
||||||
int IntoTable<TableEntityType>(string tableName);
|
int IntoTable<TableEntityType>(string tableName);
|
||||||
int IntoTable(Type TableEntityType,string tableName);
|
int IntoTable(Type TableEntityType,string tableName);
|
||||||
|
|
||||||
|
Task<int> IntoTableAsync<TableEntityType>(CancellationToken cancellationToken = default);
|
||||||
|
Task<int> IntoTableAsync(Type TableEntityType, CancellationToken cancellationToken = default);
|
||||||
|
Task<int> IntoTableAsync<TableEntityType>(string tableName, CancellationToken cancellationToken = default);
|
||||||
|
Task<int> IntoTableAsync(Type TableEntityType, string tableName, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
//bool IntoTable(Type TableEntityType, params string[] columnNameList);
|
//bool IntoTable(Type TableEntityType, params string[] columnNameList);
|
||||||
//bool IntoTable<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, bool>> whereExpression, ParameterT parameter);
|
||||||
|
Reference in New Issue
Block a user