Skip to content

Commit

Permalink
- 修复 */表达式解析问题;#1836
Browse files Browse the repository at this point in the history
  • Loading branch information
2881099 committed Jun 26, 2024
1 parent 8c9c2e6 commit 8e12ecd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Examples/base_entity/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,14 @@ static void Main(string[] args)
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion

var sqlt001 = fsql.Select<User1>()
.Where(u => u.Id == Guid.Empty)
.ToSql(u => u.GroupId / (u.Sort * 60));

sqlt001 = fsql.Select<User1>()
.Where(u => u.Id == Guid.Empty)
.ToSql(u => u.GroupId - (u.Sort + 2));

var enumToString = fsql.Select<JoinTest01>().First(s => new
{
State = ((int)s.JoinTest01Enum2).ToString()
Expand Down
7 changes: 4 additions & 3 deletions FreeSql/Internal/CommonExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,11 @@ rightExp is UnaryExpression rightExpUexp &&
if (right == "NULL") oper = oper == "=" ? " IS " : " IS NOT ";
switch (oper)
{
case "%": return _common.Mod(left, right, leftExp.Type, rightExp.Type);
case "*": return $"({left} {oper} {right})";
case "%": return $"({_common.Mod(left, right, leftExp.Type, rightExp.Type)})";
case "/":
if (leftExp.Type.IsIntegerType() && rightExp.Type.IsIntegerType()) return _common.Div(left, right, leftExp.Type, rightExp.Type);
break;
if (leftExp.Type.IsIntegerType() && rightExp.Type.IsIntegerType()) return $"({_common.Div(left, right, leftExp.Type, rightExp.Type)})";
return $"({left} {oper} {right})";
case "AND":
case "OR":
if (leftMapColumn != null) left = $"{left} = {formatSql(true, leftMapColumn.Attribute.MapType, null, null)}";
Expand Down

0 comments on commit 8e12ecd

Please sign in to comment.