Browse Source

Synchronization code

pull/31/head
sunkaixuan 2 years ago
parent
commit
1176016e7b
  1. 51
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs
  2. 7
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

51
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs

@ -732,5 +732,56 @@ 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 TableName)
{
return IntoTable(typeof(TableEntityType), TableName);
}
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,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;
}
}
}

7
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -159,6 +159,13 @@ 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<TableEntityType>(string tableName);
bool IntoTable(Type TableEntityType,string tableName);
//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);

Loading…
Cancel
Save