-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.4.4
-
Component/s: LINQ, LINQ3, Serialization
-
None
-
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();
}
}