- 修复 ISelectGrouping ToSql AsProperty 别名无效问题;

This commit is contained in:
2881099
2022-12-20 20:21:06 +08:00
parent 80cfa45f51
commit 818d335ec7
3 changed files with 37 additions and 8 deletions

View File

@ -277,15 +277,23 @@ namespace FreeSql.Internal
return false;
}
if (parent.CsType == null) parent.CsType = exp.Type;
var pdbfield = parent.DbField = ExpressionLambdaToSql(exp, getTSC());
if (parent.MapType == null || _tables?.Any(a => a.Table?.IsRereadSql == true) == true)
try
{
var findcol = SearchColumnByField(_tables, null, parent.DbField);
if (parent.MapType == null) parent.MapType = findcol?.Attribute.MapType ?? exp.Type;
if (findcol != null) pdbfield = _common.RereadColumn(findcol, pdbfield);
var pdbfield = parent.DbField = ExpressionLambdaToSql(exp, getTSC());
if (parent.MapType == null || _tables?.Any(a => a.Table?.IsRereadSql == true) == true)
{
var findcol = SearchColumnByField(_tables, null, parent.DbField);
if (parent.MapType == null) parent.MapType = findcol?.Attribute.MapType ?? exp.Type;
if (findcol != null) pdbfield = _common.RereadColumn(findcol, pdbfield);
}
field.Append(", ").Append(pdbfield);
LocalSetFieldAlias(ref index, _tables != null ||
SelectGroupingProvider._ParseExpOnlyDbField.Value != pdbfield);
}
finally
{
SelectGroupingProvider._ParseExpOnlyDbField.Value = null;
}
field.Append(", ").Append(pdbfield);
LocalSetFieldAlias(ref index, true);
return false;
}
return false;

View File

@ -31,6 +31,7 @@ namespace FreeSql.Internal.CommonProvider
_tables = tables;
}
public static ThreadLocal<string> _ParseExpOnlyDbField = new ThreadLocal<string>();
public override string ParseExp(Expression[] members)
{
ParseExpMapResult = null;
@ -52,7 +53,11 @@ namespace FreeSql.Internal.CommonProvider
}
ParseExpMapResult = read;
if (!_addFieldAlias) return read.DbField;
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false) return $"{read.DbField}{_comonExp._common.FieldAsAlias(read.DbNestedField)}";
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false)
{
_ParseExpOnlyDbField.Value = read.DbField;
return $"{read.DbField}{_comonExp._common.FieldAsAlias(read.DbNestedField)}";
}
return read.DbField;
case "Value":
var curtables = _tables;