[CSHARP-4697] Expression not supported: -i.A Created: 27/Jun/23  Updated: 28/Oct/23  Resolved: 06/Jul/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.21.0

Type: Bug Priority: Unknown
Reporter: Oleksandr Poliakov Assignee: Oleksandr Poliakov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Usage of unary negation operator is throwing ExpressionNotSupportedException exception. Code to reproduce:

 

public class MathNegationTests : Linq3IntegrationTest
{
    [Fact]
    public void Math_negation()
    {
        var collection = CreateCollection();
 
        var query = collection.AsQueryable()
            .Where(i => -i.A == 10);
 
        var results = query.ToList();
 
        results.Should().OnlyContain(i => -i.A == 10);
    }
 
    private IMongoCollection<Data> CreateCollection()
    {
        var collection = GetCollection<Data>("test");
        CreateCollection(
            collection,
            new Data { A = -10 },
            new Data { A = 5 });
        return collection;
    }
 
    private class Data
    {
        public int A { get; set; }
    }
} 



 Comments   
Comment by Githook User [ 06/Jul/23 ]

Author:

{'name': 'Oleksandr Poliakov', 'email': '31327136+sanych-sun@users.noreply.github.com', 'username': 'sanych-sun'}

Message: CSHARP-4697: Expression not supported: -i.A (#1125)
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/6b74cd96ff7dc91908d9eb2de6161de2b7937c96

Generated at Wed Feb 07 21:49:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.