[CSHARP-3989] oDATA $select support with LINQ3 Created: 08/Dec/21 Updated: 28/Oct/23 Resolved: 01/Aug/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | LINQ3, oData |
| Affects Version/s: | 2.14.1 |
| Fix Version/s: | 2.21.0 |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Dimitri Kroo | Assignee: | Oleksandr Poliakov |
| Resolution: | Fixed | Votes: | 4 |
| Labels: | LINQ | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Epic Link: | oData support for LINQ3 | ||||||||||||||||||||||||||||
| Quarter: | FY24Q2 | ||||||||||||||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||
| Documentation Changes: | Not Needed | ||||||||||||||||||||||||||||
| Documentation Changes Summary: | 1. What would you like to communicate to the user about this feature? |
||||||||||||||||||||||||||||
| Description |
|
Hello, does a new LINQ3 support oDATA with $select? I'm gettting following exception:
Thank you! |
| Comments |
| Comment by Oleksandr Poliakov [ 01/Aug/23 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Some changes were done in Driver repository to improve oData support, but new package was created for more smooth integration and will be available soon: https://github.com/mongodb/mongo-aspnetcore-odata
| ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 21/Apr/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Over time this ticket has mentioned various different issues, some of which we have solved and then new ones appeared once execution got further along before running into an issue. The latest attempt to reproduce issues mentioned in this ticket is here: https://github.com/rstam/mongo-csharp-driver/tree/csharp3989-repro Using the following query against the above branch: http://localhost:5000/odata/products?$filter=Name%20eq%20%27Apple%27&$select=Name generated the following LINQ query (captured using the debugger):
which in turn got translated to the following MQL (captured using the debugger):
This pipeline did not error on the server, but an exception was thrown client side when trying to deserialize the result (captured using the debugger):
The problem appears to originate in this part of the LINQ query:
Container is declared as type `PropertyContainer` which is abstract. When deserializing "Container : { ... }" we think the type is `PropertyContainer` because that is the type of the `Container` property. Most likely the generated MQL would need to insert an `_t : "new NamedPropertyWithNext0`1"` discriminator, but then the problem becomes that we don't yet support discriminators combined with generic types. While this ticket has resulted in several minor issues being fixed, we have now reached a more difficult problem that we are not prepared to tackle immediately, so we are putting this ticket back in the backlog for now.
| ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 07/Apr/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
The primary issue I see above is one that we have removed from an OData context and minimally reproduced in There may be other LINQ queries that OData generates that we have trouble translating. We will have to deal with them as they arise and for each one the preferred course of action will be to create a non-OData related minimal reproduction and solve that. | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by John Youngers [ 24/Mar/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Thanks James! For now I've wrapped the calls in a custom QueryProvider that will pull out the select portion of the expression, and execute that locally:
On a side note, in my use case OData would also include Converts that go from and to the same type, which was causing problems, so in the expression visitor I also have this entry:
| ||||||||||||||||||||||||||||||||||||||||||||
| Comment by James Kovacs [ 24/Mar/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Thank you to everyone who has reached out for letting us know that oData and LINQ3 are still not playing well together. We are investigating further and will update this ticket. We appreciate your patience, but wanted to let you know that we are actively pursuing this issue. | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Luca Vicenzotti [ 24/Mar/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Same issue here, $select statements in OData don't seem to work with MongoDB Linq provider V3.... | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by beqa goderdzishvili [ 16/Mar/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
What is the status of this issue? I've tried both repositories: https://github.com/imallysson/mongodb-odata and https://github.com/marcosabotinski/mongodb-dotnetcore-odata-example (with latest dependencies for net6.0), but even simple $select query doesn't work... | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by John Youngers [ 07/Mar/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
I'm running into a similar issue; high level this is where the expression ends up:
The issue is the `Model` property: Is there a way to tell the driver if it hasn't found a Serializer, to just execute that part of the expression as is (as in it doesn't need to be a part of the actual query)? | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 19/Feb/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
allysson.lp@gmail.com thanks for the additional information. I'm currently working on other tickets but I appreciate very much that you've provided a repro. | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Allysson Santos [ 18/Feb/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Hi @Robert Stam I'm facing pretty much the same issue as @Dimitri Kroo. I added to my github a project where you'll be able to reproduce the scenario.
GitHub: https://github.com/imallysson/mongodb-odata OData query: https://localhost:44373/customer2?$select=id Inside models folder you'll also find a small set of data I used.
Exception details:
| ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Dimitri Kroo [ 10/Jan/22 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Happy new year! @Robert Stam And which version of Microsoft.AspNetCore.OData have you used? Thanks! | ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Dimitri Kroo [ 20/Dec/21 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
Thank you!
The class of the object(s) is very simple. Can you confirm that in your case $select works? If yes, I will try to create a repro project.
| ||||||||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 18/Dec/21 ] | ||||||||||||||||||||||||||||||||||||||||||||
|
I have set up an OData environment and successfully executed a simple OData query using LINQ3 as the LINQ provider. In order to investigate your scenario I will need more information, including:
Hopefully that will be enough for me to reproduce your scenario. If not, I'll follow up with you. Thanks.
|