diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index ba2af102c..5f98da9ed 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -619,6 +619,14 @@ static void Main(string[] args) BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + var sqlt001 = fsql.Select() + .Where(u => u.Id == Guid.Empty) + .ToSql(u => u.GroupId / (u.Sort * 60)); + + sqlt001 = fsql.Select() + .Where(u => u.Id == Guid.Empty) + .ToSql(u => u.GroupId - (u.Sort + 2)); + var enumToString = fsql.Select().First(s => new { State = ((int)s.JoinTest01Enum2).ToString() diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index 385406315..e8cd97800 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -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)}";