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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.4.4
    • Component/s: LINQ, LINQ3, Serialization
    • None
    • Hide

      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?

      Show
      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?
    • None
    • None
    • None
    • None
    • None
    • None

      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();
              }
          }
      

              Assignee:
              Unassigned
              Reporter:
              Daniel Hegener
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: