Browse Source

Subquery join bug

pull/3/head
sunkaixuna 3 years ago
parent
commit
27120aaf51
  1. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs
  2. 2
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs
  3. 5
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs
  4. 6
      Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubInnerJoin.cs

@ -50,7 +50,7 @@ namespace SqlSugar
var joinString =string.Format(" {2} INNER JOIN {1} {0} ",
this.Context.GetTranslationColumnName(parameter.Name),
tableName,
this.Context.JoinIndex==0?name:"");
this.Context.JoinIndex==1?name:"");
var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
//var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
this.Context.JoinIndex++;

2
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubLeftJoin.cs

@ -50,7 +50,7 @@ namespace SqlSugar
var joinString =string.Format(" {2} LEFT JOIN {1} {0} ",
this.Context.GetTranslationColumnName(parameter.Name),
tableName,
this.Context.JoinIndex==0?name:"");
this.Context.JoinIndex==1?name:"");
var result = joinString+ "ON " + SubTools.GetMethodValue(Context, argExp, ResolveExpressType.WhereMultiple);
//var selfParameterName = Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
this.Context.JoinIndex++;

5
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/Items/SubSelect.cs

@ -49,7 +49,10 @@ namespace SqlSugar
this.Context.InitMappingInfo(entityType);
this.Context.RefreshMapping();
}
return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle);
if(this.Context.JoinIndex==0)
return SubTools.GetMethodValue(this.Context, exp.Arguments[0],ResolveExpressType.FieldSingle);
else
return SubTools.GetMethodValue(this.Context, exp.Arguments[0], ResolveExpressType.FieldMultiple);
}
}
}

6
Src/Asp.Net/SqlSugar/ExpressionsToSql/Subquery/SubResolve.cs

@ -135,11 +135,17 @@ namespace SqlSugar
}
isubList = isubList.OrderBy(it => it.Sort).ToList();
var isHasWhere = isubList.Where(it => it is SubWhere).Any();
var isJoin = isubList.Any(it => it is SubInnerJoin || it is SubLeftJoin);
if (isJoin)
{
this.context.JoinIndex++;
}
List<string> result = isubList.Select(it =>
{
it.HasWhere = isHasWhere;
return it.GetValue(it.Expression);
}).ToList();
this.context.JoinIndex = 0;
return result;
}
}

Loading…
Cancel
Save