Browse Source

Synchronization code

pull/31/head
sunkaixuan 2 years ago
parent
commit
5ba9ff9aac
  1. 14
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableExecuteSql.cs
  2. 49
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 13
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

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

@ -733,15 +733,15 @@ namespace SqlSugar
return result;
}
public bool IntoTable<TableEntityType>()
public int IntoTable<TableEntityType>()
{
return IntoTable(typeof(TableEntityType));
}
public bool IntoTable<TableEntityType>(string TableName)
public int IntoTable<TableEntityType>(string TableName)
{
return IntoTable(typeof(TableEntityType), TableName);
}
public bool IntoTable(Type TableEntityType)
public int IntoTable(Type TableEntityType)
{
var entityInfo=this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
var sqlInfo=this.ToSql();
@ -758,11 +758,10 @@ namespace SqlSugar
columns = columns.TrimEnd(',') + ")";
}
var sql= $" INSERT INTO {name} {columns} " + sqlInfo.Key;
this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
return true;
return this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
}
public bool IntoTable(Type TableEntityType,string TableName)
public int IntoTable(Type TableEntityType,string TableName)
{
//var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(TableEntityType);
var sqlInfo = this.ToSql();
@ -779,8 +778,7 @@ namespace SqlSugar
columns = columns.TrimEnd(',') + ")";
}
var sql = $" INSERT INTO {name} {columns} " + sqlInfo.Key;
this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
return true;
return this.Context.Ado.ExecuteCommand(sql, sqlInfo.Value);
}
}

49
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -30,13 +30,13 @@ namespace SqlSugar
this.QueryBuilder.CrossQueryItems.Add(type.FullName, configId);
return this;
}
public ISugarQueryable<T> IncludeLeftJoin(Expression<Func<T, object>> LeftObject)
public ISugarQueryable<T> IncludeLeftJoin(Expression<Func<T, object>> leftObjectExp)
{
MemberExpression memberExpression;
string navObjectName;
EntityColumnInfo navColumn, navPkColumn;
EntityInfo navEntityInfo;
ExpressionTool.GetOneToOneInfo(this.Context,LeftObject, out memberExpression, out navObjectName, out navColumn, out navEntityInfo, out navPkColumn);
ExpressionTool.GetOneToOneInfo(this.Context, leftObjectExp, out memberExpression, out navObjectName, out navColumn, out navEntityInfo, out navPkColumn);
var shortName = $"pnv_{navObjectName}";
var mainShortName = memberExpression.Expression.ToString();
this.QueryBuilder.TableShortName = mainShortName;
@ -45,6 +45,51 @@ namespace SqlSugar
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Left);
return this;
}
public ISugarQueryable<T> IncludeInnerJoin(Expression<Func<T, object>> innerObjectExt)
{
MemberExpression memberExpression;
string navObjectName;
EntityColumnInfo navColumn, navPkColumn;
EntityInfo navEntityInfo;
ExpressionTool.GetOneToOneInfo(this.Context, innerObjectExt, out memberExpression, out navObjectName, out navColumn, out navEntityInfo, out navPkColumn);
var shortName = $"pnv_{navObjectName}";
var mainShortName = memberExpression.Expression.ToString();
this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Inner);
return this;
}
public ISugarQueryable<T> IncludeFullJoin(Expression<Func<T, object>> fullObjectExp)
{
MemberExpression memberExpression;
string navObjectName;
EntityColumnInfo navColumn, navPkColumn;
EntityInfo navEntityInfo;
ExpressionTool.GetOneToOneInfo(this.Context, fullObjectExp, out memberExpression, out navObjectName, out navColumn, out navEntityInfo, out navPkColumn);
var shortName = $"pnv_{navObjectName}";
var mainShortName = memberExpression.Expression.ToString();
this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Full);
return this;
}
public ISugarQueryable<T> IncludeRightJoin(Expression<Func<T, object>> rightObjectExp)
{
MemberExpression memberExpression;
string navObjectName;
EntityColumnInfo navColumn, navPkColumn;
EntityInfo navEntityInfo;
ExpressionTool.GetOneToOneInfo(this.Context, rightObjectExp, out memberExpression, out navObjectName, out navColumn, out navEntityInfo, out navPkColumn);
var shortName = $"pnv_{navObjectName}";
var mainShortName = memberExpression.Expression.ToString();
this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Right);
return this;
}
public ISugarQueryable<T, T2> LeftJoin<T2>(ISugarQueryable<T2> joinQueryable, Expression<Func<T, T2, bool>> joinExpression)
{

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

@ -23,7 +23,10 @@ namespace SqlSugar
//ISugarQueryable<T> CrossQueryWithAttr();
ISugarQueryable<T> CrossQuery<Type>(string configId);
ISugarQueryable<T> CrossQuery(Type type ,string configId);
ISugarQueryable<T> IncludeLeftJoin(Expression<Func<T, object>> LeftObject);
ISugarQueryable<T> IncludeLeftJoin(Expression<Func<T, object>> leftObjectExp);
ISugarQueryable<T> IncludeInnerJoin(Expression<Func<T, object>> innerObjectExp);
ISugarQueryable<T> IncludeRightJoin(Expression<Func<T, object>> rightObjectExp);
ISugarQueryable<T> IncludeFullJoin(Expression<Func<T, object>> fullObjectExp);
ISugarQueryable<T, T2> LeftJoin<T2>(ISugarQueryable<T2> joinQueryable, Expression<Func<T, T2, bool>> joinExpression);
ISugarQueryable<T, T2> InnerJoin<T2>(ISugarQueryable<T2> joinQueryable, Expression<Func<T, T2, bool>> joinExpression);
ISugarQueryable<T, T2> RightJoin<T2>(ISugarQueryable<T2> joinQueryable, Expression<Func<T, T2, bool>> joinExpression);
@ -160,10 +163,10 @@ namespace SqlSugar
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);
int IntoTable<TableEntityType>();
int IntoTable(Type TableEntityType);
int IntoTable<TableEntityType>(string tableName);
int 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);

Loading…
Cancel
Save