[CSHARP-4762] Select with lambda parameter that is a base type of collection document type throws Created: 18/Aug/23 Updated: 10/Oct/23 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 2.21.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Blocker - P1 |
| Reporter: | Dimitri Kroo | Assignee: | Robert Stam |
| Resolution: | Unresolved | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
Hi,
using expression variables like below doesn't work with Linq V3 Expression<Func<ParentBaseClass, ParentBaseClass>> select = x => ; collection.AsQueryable().Select(select).ToList();
Best regards Dimitri |
| Comments |
| Comment by Robert Stam [ 04/Oct/23 ] | ||||||||||||
|
Minimal repro:
where B and C are declared as:
| ||||||||||||
| Comment by Dimitri Kroo [ 02/Oct/23 ] | ||||||||||||
|
Thank you for workaround!
| ||||||||||||
| Comment by Robert Stam [ 30/Sep/23 ] | ||||||||||||
|
I think I am able to reproduce your issue. The exception I get is:
Is that the same exception you get? I don't think the issue is related to In this case your `select` variable type does not match the collection type (at least not exactly). If you declare your `select` variable instead as:
the code works. I understand that your code as you provided should work, I'm only offering the above as a workaround. When the `select` variable is of type `Expression<Func<ParentBaseClass, ParentBaseClass>>` there is an implicit conversion of `IMongoQueryable<ParentClass>` to `IQueryable<ParentBaseClass>` when `Select` is called, and that's what's confusing the LINQ3 translator.
| ||||||||||||
| Comment by Shiya Kohn [ 24/Aug/23 ] | ||||||||||||
|
robert@mongodb.com it seems that this is related to | ||||||||||||
| Comment by PM Bot [ 18/Aug/23 ] | ||||||||||||
|
Hi dimitri.kroo@baramundi.com, thank you for reporting this issue! The team will look into it and get back to you soon. |