-
Type:
Improvement
-
Resolution: Done
-
Priority:
Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Dotnet Drivers
-
None
-
None
-
None
-
None
-
None
-
None
LINQ queries that perform arithmetic inside a C# checked { } block fail with ExpressionNotSupportedException.
CSHARP-5606 added support for ExpressionType.ConvertChecked but did not cover the checked arithmetic node kinds the compiler also emits in a checked context: AddChecked, SubtractChecked, MultiplyChecked, and NegateChecked. These are equivalent to their unchecked siblings for translation purposes (MongoDB has no overflow-checked arithmetic operators), so each should translate identically to Add / Subtract / Multiply / Negate.
var collection = database.GetCollection<C>("c"); Expression<Func<C, R>> projection; checked { projection = x => new R { V = x.A + x.B }; } var query = collection.AsQueryable().Select(projection); var stages = query.ToString(); // or .ToList()
Expected: translates to { $project : { V :
{ $add : ['$A', '$B'] }, _id : 0 } } — identical to the unchecked form.
Actual: throws MongoDB.Driver.Linq.ExpressionNotSupportedException : Expression not supported: (x.A + x.B).
Same failure occurs for , *, unary -, and enum +/ when written inside a checked block, in both Select/$project projections and Where/$match predicates.
- blocks
-
EF-249 Support translation in a C# checked context
-
- Blocked
-