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

Expression based queries don't work for properties without a setter

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 2.4.4
    • Linq, LINQ3, Serialization

    Description

      When trying to issue a query using an expression that contains a property with no setter the serialization fails:

      An unhandled exception of type 'System.InvalidOperationException' occurred in MongoDB.Driver.dll
       
      Additional information: {document}.PropertyThatDoesNotWork is not supported.
      

      Here is some test code that demonstrates the issue:

          public class Test
          {
              public ObjectId Id { get; set; }
              public string Field;
              public string PropertyThatWorks { get; set; }
              public string PropertyThatDoesNotWork { get; }
          }
       
          class Program
          {
              private static readonly IMongoCollection<Test> collection = new MongoClient().GetDatabase("test").GetCollection<Test>("c");
              
              static void Main(string[] args)
              {
                  /* 1 - works */ var result = collection.Find(c => c.Field == "test").ToList();
                  /* 2 - works */ result = collection.Find(c => c.PropertyThatWorks == "test").ToList();
                  /* 3 - FAILS */ result = collection.Find(c => c.PropertyThatDoesNotWork == "test").ToList();
              }
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: