[CSHARP-1379] Support comparison operators with constant on left hand side Created: 13/Aug/15  Updated: 07/Apr/23  Resolved: 22/Mar/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.0.1
Fix Version/s: 2.2.3

Type: Bug Priority: Minor - P4
Reporter: Sheila Kinsella Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: linq, regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

Comparison queries in LINQ where the constant is on the left hand side throw an ArgumentException.

For example:

collection.Find(user => DateTime.Now > user.UpdatedDate);

Looks like a regression of CSHARP-431



 Comments   
Comment by Craig Wilson [ 22/Mar/16 ]

Thanks Sheila, I've marked this as resolved in 2.2.3 and closed the ticket.

Comment by Sheila Kinsella [ 22/Mar/16 ]

Hi Craig

The below code produces an error on 2.0.1 but runs successfully on 2.2.3, I guess the issue has been resolved since.

using System;
using MongoDB.Bson;
using MongoDB.Driver;
 
namespace ConsoleApplication1
{
    public class Program
    {
 
        private static void Main(string[] args)
        {
            var client = new MongoClient("mongodb://localhost:27017");
            var db = client.GetDatabase("foo");
            var col = db.GetCollection<User>("Test");
 
            var users = col.Find(x => DateTime.UtcNow > x.UpdatedDate).ToListAsync().Result;
 
            Console.WriteLine(users.Count);
            Console.WriteLine("Press Enter");
            Console.ReadLine();
        }
 
        private class User
        {
            public ObjectId Id { get; set; }
            public DateTime UpdatedDate { get; set; }
        }
    }
}

Comment by Craig Wilson [ 11/Mar/16 ]

Hi Sheila,

I cannot reproduce this. I used the following code:

using System;
using MongoDB.Bson;
using MongoDB.Driver;
 
namespace TestBugs
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new MongoClient();
            var db = client.GetDatabase("csharp1379");
            var col = db.GetCollection<User>("users");
 
            col.InsertOne(new User { UpdatedDate = DateTime.Now.AddYears(-1) });
 
            var users = col.Find(x => DateTime.Now > x.UpdatedDate).ToList();
 
            Console.WriteLine(users.Count);
            Console.WriteLine("Press Enter");
            Console.ReadLine();
        }
 
        private class User
        {
            public ObjectId Id { get; set; }
            public DateTime UpdatedDate { get; set; }
        }
    }
}

Perhaps you could provide a console application that demonstrates the problem.

Craig

Comment by Sheila Kinsella [ 14/Aug/15 ]

I tested this with a property of type int and it worked fine so maybe this is only an issue with DateTime

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