Skip to content

Commit 8e12ecd

Browse files
committed
- 修复 */表达式解析问题;#1836
1 parent 8c9c2e6 commit 8e12ecd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Examples/base_entity/Program.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,14 @@ static void Main(string[] args)
619619
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
620620
#endregion
621621

622+
var sqlt001 = fsql.Select<User1>()
623+
.Where(u => u.Id == Guid.Empty)
624+
.ToSql(u => u.GroupId / (u.Sort * 60));
625+
626+
sqlt001 = fsql.Select<User1>()
627+
.Where(u => u.Id == Guid.Empty)
628+
.ToSql(u => u.GroupId - (u.Sort + 2));
629+
622630
var enumToString = fsql.Select<JoinTest01>().First(s => new
623631
{
624632
State = ((int)s.JoinTest01Enum2).ToString()

FreeSql/Internal/CommonExpression.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,10 +946,11 @@ rightExp is UnaryExpression rightExpUexp &&
946946
if (right == "NULL") oper = oper == "=" ? " IS " : " IS NOT ";
947947
switch (oper)
948948
{
949-
case "%": return _common.Mod(left, right, leftExp.Type, rightExp.Type);
949+
case "*": return $"({left} {oper} {right})";
950+
case "%": return $"({_common.Mod(left, right, leftExp.Type, rightExp.Type)})";
950951
case "/":
951-
if (leftExp.Type.IsIntegerType() && rightExp.Type.IsIntegerType()) return _common.Div(left, right, leftExp.Type, rightExp.Type);
952-
break;
952+
if (leftExp.Type.IsIntegerType() && rightExp.Type.IsIntegerType()) return $"({_common.Div(left, right, leftExp.Type, rightExp.Type)})";
953+
return $"({left} {oper} {right})";
953954
case "AND":
954955
case "OR":
955956
if (leftMapColumn != null) left = $"{left} = {formatSql(true, leftMapColumn.Attribute.MapType, null, null)}";

0 commit comments

Comments
 (0)