Browse Source

Update Include Join

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

14
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<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)
{
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
}

8
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<T> IncludeInnerJoin(Expression<Func<T, object>> 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<T> IncludeFullJoin(Expression<Func<T, object>> 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<T> IncludeRightJoin(Expression<Func<T, object>> 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;
}

Loading…
Cancel
Save