[CSHARP-900] Support downcasting object in LINQ queries Created: 23/Jan/14 Updated: 14/Nov/19 Resolved: 18/Feb/14 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.8.3 |
| Fix Version/s: | 1.9 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Robert Stam | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
It would be nice if given a class like:
One could write LINQ queries like:
Normally we deduce the serialized form of the value from the type information of the field, but in this case we would have to deduce the desired type from the cast used in the query. Not sure what all the ramifications of this feature are... it's possible that there is more to it than initially meets the eye and this might not turn out to be easily doable. So the first step is to properly research the feasability of this feature. |
| Comments |
| Comment by Sebastian Inones [ 14/Nov/19 ] | |||||||||||||||||||
|
Ciao @Nicola Cassolato, Sorry for the late late reply. Truth be told, the issue was on my code (that was the most reasonable thing). Sebastian | |||||||||||||||||||
| Comment by Nicola Cassolato [ 05/Aug/19 ] | |||||||||||||||||||
|
ciao @Sebastian Inones,
I was able to solve using 'as' instead of doing a CAST. Using my example, this kind of query works
var cursor = collectionExample.Find(x=> (x.Field as TextValue).FieldValue = "bar")
Hope this helps Nicola
| |||||||||||||||||||
| Comment by Sebastian Inones [ 01/Aug/19 ] | |||||||||||||||||||
|
I have a quite similar issue as @Nicola Cassolato.
For instance, the string Pointer member is the one that I will use for casting.. So, when I create a filter (in my wrapper) like the one below and then when the Find query gets executed I will throw the same type of exception as the comments above: * {document} {PropertyValue}) is not supported.*
I just pasted the relevant parts of my code. | |||||||||||||||||||
| Comment by Sudhir Thanki [ 05/Jun/18 ] | |||||||||||||||||||
|
I have same issue while converting string value to datetime in a query. It throws following exception:
I used mongodb 2.6.0 nuget package
| |||||||||||||||||||
| Comment by Nicola Cassolato [ 18/Jan/18 ] | |||||||||||||||||||
|
I'm sorry to re-open an old ticket but I feel this is the right place. I've found a scenario where casting a field of type Interface to a specific type is not working.
The code in example will return an error 'Convert( {document}.TestProperty, TextValue).GlobalValue is not supported | |||||||||||||||||||
| Comment by Githook User [ 18/Feb/14 ] | |||||||||||||||||||
|
Author: {u'username': u'ddebilt', u'name': u'ddebilt', u'email': u'dan.debilt@gmail.com'}Message: | |||||||||||||||||||
| Comment by Githook User [ 18/Feb/14 ] | |||||||||||||||||||
|
Author: {u'username': u'ddebilt', u'name': u'ddebilt', u'email': u'dan.debilt@gmail.com'}Message: | |||||||||||||||||||
| Comment by Githook User [ 18/Feb/14 ] | |||||||||||||||||||
|
Author: {u'username': u'ddebilt', u'name': u'ddebilt', u'email': u'dan.debilt@gmail.com'}Message: | |||||||||||||||||||
| Comment by Githook User [ 18/Feb/14 ] | |||||||||||||||||||
|
Author: {u'username': u'ddebilt', u'name': u'ddebilt', u'email': u'dan.debilt@gmail.com'}Message: | |||||||||||||||||||
| Comment by Stefan [ 17/Feb/14 ] | |||||||||||||||||||
|
Thanks Craig, Just after I wrote this post I thought "bugger it I will patch it myself" only to go to github and see the existing pull request Cheers | |||||||||||||||||||
| Comment by Craig Wilson [ 17/Feb/14 ] | |||||||||||||||||||
|
Hi Stefan, Yes, it can be supported. We just had a pull request for this exact issue: https://github.com/mongodb/mongo-csharp-driver/pull/172. If you'd like, feel free to test out the pull request and let us know if it fixes your issue. Craig | |||||||||||||||||||
| Comment by Stefan [ 17/Feb/14 ] | |||||||||||||||||||
|
Do we have any more indication on this issue as to if it is something that can be supported? I am trying to write a custom query language > linq parser and need to be able to case a collection of IList<Property> where Property.Value is of type object, the only way I can do this at the moment is to replace: (... && (int)prop.Value < 1) with: (... && Query.LT("Value", new BsonInt64(1)).Inject()) This works fine, but it removes the idea goal of being able to run the exact same queries over in memory objects as well as against the database. Thanks | |||||||||||||||||||
| Comment by Robert Stam [ 23/Jan/14 ] | |||||||||||||||||||
|
Initially created in response to user feedback at: |