diff --git a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavSelectHelper.cs b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavSelectHelper.cs index 30283c2d4..2b9d155bd 100644 --- a/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavSelectHelper.cs +++ b/Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/NavSelectHelper.cs @@ -21,7 +21,7 @@ namespace SqlSugar .Select(expression) .ToList(); var includeQueryable = queryableProvider.Clone(); - includeQueryable.Select(GetGroupSelect(typeof(T), queryableProvider.Context)); + includeQueryable.Select(GetGroupSelect(typeof(T), queryableProvider.Context,queryableProvider.QueryBuilder)); includeQueryable.QueryBuilder.NoCheckInclude=true; MegerList(result, includeQueryable.ToList(), sqlfuncQueryable.Context); } @@ -53,7 +53,7 @@ namespace SqlSugar .Select(expression) .ToListAsync(); var includeQueryable = queryableProvider.Clone(); - includeQueryable.Select(GetGroupSelect(typeof(T), queryableProvider.Context)); + includeQueryable.Select(GetGroupSelect(typeof(T), queryableProvider.Context, queryableProvider.QueryBuilder)); includeQueryable.QueryBuilder.NoCheckInclude = true; MegerList(result,await includeQueryable.ToListAsync(), sqlfuncQueryable.Context); } @@ -75,13 +75,20 @@ namespace SqlSugar return result; } - private static string GetGroupSelect(Type type,SqlSugarProvider context) + private static string GetGroupSelect(Type type,SqlSugarProvider context,QueryBuilder queryBuilder) { var entity = context.EntityMaintenance.GetEntityInfo(type); List selector = new List(); foreach (var item in entity.Columns.Where(it=>it.IsIgnore==false)) { - selector.Add($" min({item.DbColumnName}) as {item.DbColumnName}"); + if (queryBuilder.TableShortName.HasValue()) + { + selector.Add($" min({queryBuilder.TableShortName}.{item.DbColumnName}) as {item.DbColumnName}"); + } + else + { + selector.Add($" min({item.DbColumnName}) as {item.DbColumnName}"); + } } return string.Join(",", selector); } diff --git a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs index 9158d3332..aa1262d13 100644 --- a/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs +++ b/Src/Asp.NetCore2/SqlSugar/ExpressionsToSql/ResolveItems/OneToManyNavgateExpression.cs @@ -152,6 +152,10 @@ namespace SqlSugar if (this.whereSql.HasValue()) { mapper.Sql = mapper.Sql.TrimEnd(')'); + if (this.whereSql.Contains($" {PropertyShortName}.")) + { + this.whereSql = this.whereSql.Replace($" {PropertyShortName}.", $" {this.ProPertyEntity.DbTableName}_1."); + } mapper.Sql = mapper.Sql + " AND " + this.whereSql+")"; } if (MethodName == "Any")