diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs index 949be3aa4..b552cfdaa 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -999,6 +999,18 @@ namespace SqlSugar #endregion #region Other + private string GetTableName(EntityColumnInfo navPkColumn, string tableName) + { + var attr = navPkColumn?.PropertyInfo?.PropertyType?.GetCustomAttribute(); + 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 entityColumnInfos,string sql, ReadOnlyCollection parameters, List columnsResult, int parameterIndex1) { var lowerSql = sql.ToLower(); @@ -1824,7 +1836,7 @@ namespace SqlSugar this.QueryBuilder.IsSqlQuery == false && !this.QueryBuilder.AsTables.Any() && this.QueryBuilder.IsSingle() && - this.QueryBuilder.WhereInfos.Any(); + (this.QueryBuilder.WhereInfos.Any()|| this.QueryBuilder.SelectValue is Expression); } #endregion } diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 1bb0d497d..3087b720d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -42,7 +42,7 @@ namespace SqlSugar this.QueryBuilder.TableShortName = mainShortName; var onWhere = $"{shortName}.{navPkColumn.DbColumnName}={mainShortName}.{navColumn.DbColumnName}"; 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; } public ISugarQueryable IncludeInnerJoin(Expression> innerObjectExt) @@ -57,7 +57,7 @@ namespace SqlSugar 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); + this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Inner); return this; } public ISugarQueryable IncludeFullJoin(Expression> fullObjectExp) @@ -72,7 +72,7 @@ namespace SqlSugar 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); + this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Full); return this; } public ISugarQueryable IncludeRightJoin(Expression> rightObjectExp) @@ -87,7 +87,7 @@ namespace SqlSugar 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); + this.AddJoinInfo(GetTableName(navPkColumn, navEntityInfo.DbTableName), shortName, onWhere, JoinType.Right); return this; }