- 修复 ISelect Sum/First 子查询时,若子查询实体类与主查询一样时,导致的 bug;

This commit is contained in:
28810
2019-08-12 16:53:13 +08:00
parent ecda6d8f49
commit 6d9b6b6670
4 changed files with 14 additions and 8 deletions

View File

@ -817,12 +817,18 @@ namespace FreeSql.Internal
case "Min":
case "Max":
case "Avg":
var sqlSum = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { $"{exp3.Method.Name.ToLower()}({ExpressionLambdaToSql(exp3.Arguments.FirstOrDefault(), tsc)})" })?.ToString();
var tscClone1 = tsc.CloneDisableDiyParse();
tscClone1.isDisableDiyParse = false;
tscClone1._tables = fsqltables;
var sqlSum = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { $"{exp3.Method.Name.ToLower()}({ExpressionLambdaToSql(exp3.Arguments.FirstOrDefault(), tscClone1)})" })?.ToString();
if (string.IsNullOrEmpty(sqlSum) == false)
return $"({sqlSum.Replace("\r\n", "\r\n\t")})";
break;
case "First":
var sqlFirst = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { ExpressionLambdaToSql(exp3.Arguments.FirstOrDefault(), tsc) })?.ToString();
var tscClone2 = tsc.CloneDisableDiyParse();
tscClone2.isDisableDiyParse = false;
tscClone2._tables = fsqltables;
var sqlFirst = fsqlType.GetMethod("ToSql", new Type[] { typeof(string) })?.Invoke(fsql, new object[] { ExpressionLambdaToSql(exp3.Arguments.FirstOrDefault(), tscClone2) })?.ToString();
if (string.IsNullOrEmpty(sqlFirst) == false)
return $"({sqlFirst.Replace("\r\n", "\r\n\t")})";
break;