Browse Source

Synchronization code

pull/31/head
sunkaixuan 2 years ago
parent
commit
a2ad462bb4
  1. 14
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs
  2. 8
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

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

@ -999,6 +999,18 @@ namespace SqlSugar
#endregion #endregion
#region Other #region Other
private string GetTableName(EntityColumnInfo navPkColumn, string tableName)
{
var attr = navPkColumn?.PropertyInfo?.PropertyType?.GetCustomAttribute<TenantAttribute>();
var configId = ((object)this.Context.CurrentConnectionConfig.ConfigId).ObjToString();
if (attr != null && configId != attr.configId.ObjToString())
{
var dbName = this.Context.Root.GetConnection(attr.configId).Ado.Connection.Database;
tableName = this.QueryBuilder.LambdaExpressions.DbMehtods.GetTableWithDataBase
(this.QueryBuilder.Builder.GetTranslationColumnName(dbName), this.QueryBuilder.Builder.GetTranslationColumnName(tableName));
}
return tableName;
}
protected string AppendSelect(List<EntityColumnInfo> entityColumnInfos,string sql, ReadOnlyCollection<ParameterExpression> parameters, List<EntityColumnInfo> columnsResult, int parameterIndex1) protected string AppendSelect(List<EntityColumnInfo> entityColumnInfos,string sql, ReadOnlyCollection<ParameterExpression> parameters, List<EntityColumnInfo> columnsResult, int parameterIndex1)
{ {
var lowerSql = sql.ToLower(); var lowerSql = sql.ToLower();
@ -1824,7 +1836,7 @@ namespace SqlSugar
this.QueryBuilder.IsSqlQuery == false && this.QueryBuilder.IsSqlQuery == false &&
!this.QueryBuilder.AsTables.Any() && !this.QueryBuilder.AsTables.Any() &&
this.QueryBuilder.IsSingle() && this.QueryBuilder.IsSingle() &&
this.QueryBuilder.WhereInfos.Any(); (this.QueryBuilder.WhereInfos.Any()|| this.QueryBuilder.SelectValue is Expression);
} }
#endregion #endregion
} }

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

@ -42,7 +42,7 @@ namespace SqlSugar
this.QueryBuilder.TableShortName = mainShortName; this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}"; var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems); UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Left); this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Left);
return this; return this;
} }
public ISugarQueryable<T> IncludeInnerJoin(Expression<Func<T, object>> innerObjectExt) public ISugarQueryable<T> IncludeInnerJoin(Expression<Func<T, object>> innerObjectExt)
@ -57,7 +57,7 @@ namespace SqlSugar
this.QueryBuilder.TableShortName = mainShortName; this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}"; var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems); UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Inner); this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Inner);
return this; return this;
} }
public ISugarQueryable<T> IncludeFullJoin(Expression<Func<T, object>> fullObjectExp) public ISugarQueryable<T> IncludeFullJoin(Expression<Func<T, object>> fullObjectExp)
@ -72,7 +72,7 @@ namespace SqlSugar
this.QueryBuilder.TableShortName = mainShortName; this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}"; var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems); UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Full); this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Full);
return this; return this;
} }
public ISugarQueryable<T> IncludeRightJoin(Expression<Func<T, object>> rightObjectExp) public ISugarQueryable<T> IncludeRightJoin(Expression<Func<T, object>> rightObjectExp)
@ -87,7 +87,7 @@ namespace SqlSugar
this.QueryBuilder.TableShortName = mainShortName; this.QueryBuilder.TableShortName = mainShortName;
var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}"; var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}";
UtilMethods.IsNullReturnNew(this.Context.TempItems); UtilMethods.IsNullReturnNew(this.Context.TempItems);
this.AddJoinInfo(navEntityInfo.DbTableName, shortName, onWhere, JoinType.Right); this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Right);
return this; return this;
} }

Loading…
Cancel
Save