Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1509

FilterDefinitionBuilder Where can result in an InvalidCastException when filter is rendered

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.4
    • Affects Version/s: 2.2
    • Component/s: Linq
    • None

      Given the following class:

      public class C
      {
          public int Id;
          public int Prop;
      }
      

      the following query will throw an InvalidCastException:

      var builder = Builders<C>.Filter;
      var value = 2067L; // note: value is a long
      var filter = builder.Where(x => x.Prop == value); // note: x.Prop is an int
      var document = await collection.Find(filter).FirstOrDefaultAsync();
      

      Note: this worked in 2.0.2 but no longer works in 2.1.1+.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: