Summary
After upgrading to the 2.19 (and 2.19.1) driver with the LINQ3 provider enabled by default, our expression-based projections are no longer retrieving all of the expected fields. Tested against a standalone 5.0.15 server.
How to Reproduce
The attached example includes the connection string and name of the database as arguments in the launchSettings.json. The relevant part is:
var filter = Builders<Model>.Filter.Eq(m => m.Id, modelToInsert.Id); var foundProjection = await collection.Find(filter) .Project(Builders<Model>.Projection.Expression( m => new View(m.Id) { })) .SingleAsync();
Specifically, having both constructor parameters and initializer braces (whether we actually assign to any properties or not) prevents the driver from retrieving the fields being passed to the constructor. In this case, the result is that the retrieved object has a null ID property even though we requested the ID field via the expression. Removing the {} after "new View(m.Id)" avoids the issue (though in real code we are retrieving additional properties). Removing the Version property from the View class such that all properties are set via constructor also avoids the issue.
Additional Background
We ran into this issue after upgrading to the 2.19 driver, presumably because of the switch to the LINQ3 provider by default. Manually switching back to the LINQ2 provider avoids the issue.
- is related to
-
CSHARP-4591 AutoMap constructors for mutable classes also
- Backlog