This commit is contained in:
2881099 2024-02-01 14:19:34 +08:00
parent 7e897784a2
commit 1b807f3cf6
2 changed files with 21 additions and 33 deletions

View File

@ -25,8 +25,7 @@ namespace FreeSql.Internal
public ParameterExpression _lambdaParameter;
public ReadAnonymousTypeInfo _map;
public string _field;
public ReadAnonymousTypeInfo ParseExpMapResult { get; internal protected set; }
public ColumnInfo ParseExpColumnResult { get; internal protected set; }
public ReadAnonymousTypeInfo ParseExpMapResult { get; protected set; }
public abstract string ParseExp(Expression[] members);
}
@ -860,10 +859,8 @@ namespace FreeSql.Internal
}
Type oldMapType = null;
if (tsc.diymemexp != null) tsc.diymemexp.ParseExpColumnResult = null;
var left = ExpressionLambdaToSql(leftExp, tsc);
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left) ??
tsc.diymemexp?.ParseExpColumnResult; //group by emum -> MapType(string) #1727
var leftMapColumn = SearchColumnByField(tsc._tables, tsc.currentTable, left);
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;
@ -873,7 +870,6 @@ namespace FreeSql.Internal
(leftMapColumn.Table.AsTableColumn == leftMapColumn && rightExp.IsParameter() == false)) ? //自动分表
formatSql(Expression.Lambda(rightExp).Compile().DynamicInvoke(), leftMapColumn.Attribute.MapType, leftMapColumn, tsc.dbParams) :
ExpressionLambdaToSql(rightExp, tsc);
if (isLeftMapType) tsc.SetMapTypeReturnOld(leftMapColumn.Attribute.MapType);
if (right != "NULL" && isLeftMapType &&
//判断参数化后的bug
!(right.Contains('@') || right.Contains('?') || right.Contains(':')) &&
@ -900,7 +896,6 @@ namespace FreeSql.Internal
(rightMapColumn.Table.AsTableColumn == rightMapColumn && leftExp.IsParameter() == false)) ? //自动分表
formatSql(Expression.Lambda(leftExp).Compile().DynamicInvoke(), rightMapColumn.Attribute.MapType, rightMapColumn, tsc.dbParams) :
ExpressionLambdaToSql(leftExp, tsc);
if (isRightMapType) tsc.SetMapTypeReturnOld(rightMapColumn.Attribute.MapType);
if (left != "NULL" && isRightMapType &&
//判断参数化后的bug
!(left.Contains('@') || left.Contains('?') || left.Contains(':')) &&

View File

@ -36,11 +36,9 @@ namespace FreeSql.Internal.CommonProvider
public override string ParseExp(Expression[] members)
{
ParseExpMapResult = null;
ParseExpColumnResult = null;
if (members.Any() == false)
{
ParseExpMapResult = _map;
ParseExpColumnResult = ParseExpMapResult.GetColumn();
return _map.DbField;
}
var firstMember = ((members.FirstOrDefault() as MemberExpression)?.Expression as MemberExpression);
@ -55,7 +53,6 @@ namespace FreeSql.Internal.CommonProvider
if (read == null) return null;
}
ParseExpMapResult = read;
ParseExpColumnResult = ParseExpMapResult.GetColumn();
if (!_addFieldAlias) return read.DbField;
if (_flagNestedFieldAlias) return read.DbField;
if (_comonExp.EndsWithDbNestedField(read.DbField, read.DbNestedField) == false)
@ -85,7 +82,6 @@ namespace FreeSql.Internal.CommonProvider
members[a] = replaceVistor.Modify(members[a], replaceMember, curtable.Parameter);
var ret = _select._diymemexpWithTempQuery.ParseExp(members);
ParseExpMapResult = _select._diymemexpWithTempQuery.ParseExpMapResult;
ParseExpColumnResult = ParseExpMapResult.GetColumn();
return ret;
}
}
@ -134,10 +130,7 @@ namespace FreeSql.Internal.CommonProvider
return null;
}
}
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);
ParseExpColumnResult = tsc.mapColumnTmp;
return result;
return _comonExp.ExpressionLambdaToSql(retExp, new CommonExpression.ExpTSC { _tables = _tables, _tableRule = _select._tableRule, tbtype = SelectTableInfoType.From, isQuoteName = true, isDisableDiyParse = true, style = CommonExpression.ExpressionStyle.Where });
}
return null;
}