- 修复 Enum -> MapType(string) + GroupBy 解析问题;#1727

This commit is contained in:
2881099
2024-01-26 18:59:43 +08:00
parent d32ba64bab
commit 2598451261
4 changed files with 185 additions and 49 deletions

View File

@ -25,7 +25,7 @@ namespace FreeSql.Internal
public ParameterExpression _lambdaParameter;
public ReadAnonymousTypeInfo _map;
public string _field;
public ReadAnonymousTypeInfo ParseExpMapResult { get; protected set; }
public ReadAnonymousTypeInfo ParseExpMapResult { get; internal protected set; }
public abstract string ParseExp(Expression[] members);
}
@ -859,8 +859,10 @@ namespace FreeSql.Internal
}
Type oldMapType = null;
if (tsc.diymemexp != null) tsc.diymemexp.ParseExpMapResult = null;
var left = ExpressionLambdaToSql(leftExp, tsc);
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left);
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left) ??
(tsc.diymemexp?.ParseExpMapResult?.Table?.ColumnsByCs.TryGetValue(tsc.diymemexp.ParseExpMapResult.CsName, out var dmcol) == true ? dmcol : null); //group by emum -> MapType(string) #1727
var isLeftMapType = leftMapColumn != null && new[] { "AND", "OR", "*", "/", "+", "-" }.Contains(oper) == false && (leftMapColumn.Attribute.MapType != rightExp.Type || leftMapColumn.CsType != rightExp.Type);
ColumnInfo rightMapColumn = null;
var isRightMapType = false;

View File

@ -130,7 +130,19 @@ namespace FreeSql.Internal.CommonProvider
return null;
}
}
return _comonExp.ExpressionLambdaToSql(retExp, new CommonExpression.ExpTSC { _tables = _tables, _tableRule = _select._tableRule, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = true, style = CommonExpression.ExpressionStyle.Where });
var tsc = new CommonExpression.ExpTSC { _tables = _tables, _tableRule = _select._tableRule, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = true, style = CommonExpression.ExpressionStyle.Where };
var result = _comonExp.ExpressionLambdaToSql(retExp, tsc);
//ParseExpMapResult = result
if (tsc.mapColumnTmp != null)
ParseExpMapResult = new ReadAnonymousTypeInfo
{
Property = tsc.mapColumnTmp.Table.Properties[tsc.mapColumnTmp.CsName],
CsName = tsc.mapColumnTmp.CsName,
CsType = tsc.mapColumnTmp.CsType, //dtoProp.PropertyType,
MapType = tsc.mapColumnTmp.Attribute.MapType,
Table = tsc.mapColumnTmp.Table
};
return result;
}
return null;
}