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

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

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.4
    • Component/s: Linq, LINQ3, Serialization
    • 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?

      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 Unassigned
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: