[CSHARP-4505] The LINQ3 provider does not support projection to a class taking a BsonDocument in its constructor Created: 30/Jan/23 Updated: 27/Oct/23 Resolved: 06/Feb/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3 |
| Affects Version/s: | 2.19.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Cédric Luthi | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Case: | (copied to CRM) |
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
| Description |
SummaryThe LINQ3 provider does not support projection to a class taking a BsonDocument in its constructor (the V2 provider supports it). How to Reproduce
Run with the V2 driver (dotnet run V2): ✅ works as expected
Run with the V3 driver (dotnet run V3): ❌ ExpressionNotSupportedException
Additional BackgroundThe Hangfire.Mongo project uses this pattern (Find + Project) a lot so it's impossible to migrate to the LINQ3 provider. |
| Comments |
| Comment by Robert Stam [ 06/Feb/23 ] | |||||||||||
|
For the example given in this issue you can make it work by factoring out the client side projection. Change:
to:
| |||||||||||
| Comment by Esha Bhargava [ 03/Feb/23 ] | |||||||||||
|
cedric.luthi@gmail.com Thank you for reporting this issue. We'll look into it and get back to you soon. | |||||||||||
| Comment by Cédric Luthi [ 03/Feb/23 ] | |||||||||||
|
The V2 provider was in fact doing client side evaluation for those queries (like EF Core used to do before version 3.0). Throwing an ExpressionNotSupportedException is indeed a better approach (like EF Core does for version 3.0 upwards). The problematic queries in Hangfire.Mongo have been addressed in pull request #339 and released in version 1.9.2. This issue can be closed. |