[CSHARP-1270] OData IQueryable Filters don't translate to MongoDB Created: 07/May/15  Updated: 26/May/15  Resolved: 14/May/15

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.0
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Calvin Hopkins Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

ODataQueryOptions.Filter uses Odata filters. These do not translate through to MongoDB syntax. This prevents MongoDB from being the backing store for an OData endpoint without plenty of extra work.

Ex: StartsWith is enabled through a regular Queryable/Where Expression has call syntax Syntax ".Call $e.Name.StartsWith(\"X\")". From the OData query, the RawFilter bceomes "startswith(Name,'MPMD')" The MongoDB Driver doesn't understand that format.

More examples of queries which don't translate: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/



 Comments   
Comment by Craig Wilson [ 26/May/15 ]

Hi Calvin,

Have you built the driver from source? As mentioned previously, we don't have the rewritten LINQ support in the 2.0 driver yet. It exists in master, but hasn't been distributed yet. In addition, we haven't spent anytime attempting to support OData, so I'm sure there are some/many things that don't work. If you'd like to provide me a sample project that illustrates the error you are seeing, I'll take a look.

Craig

Comment by Calvin Hopkins [ 26/May/15 ]

Hi Craig,
I just upgraded to the new client (v2.0), however I'm still unable to pipe through the OData query option Expression for startswith.

Extracting out the Expression from the ODataQuery gives me the following:
"$it => ((Convert(($it.Id == value(System.Web.Http.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.Int32]).TypedProperty)) AndAlso IIF((($it.ItemId == null) Or (value(System.Web.Http.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.String]).TypedProperty == null)), null, Convert($it.ItemId.StartsWith(value(System.Web.Http.OData.Query.Expressions.LinqParameterContainer+TypedLinqParameterContainer`1[System.String]).TypedProperty)))) == True)"

However, I then get the following exception when I pass that into the Predicate Translator:
(Convert((Serialization(Id) == 20150525)) AndAlso IIF(((Serialization(ItemId) == null) Or False), null, Convert(Serialization(ItemId).StartsWith("Environment")))) is not supported.

at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetSerializationInfo(Expression expression) in d:\jenkins\workspace\mongo-csharp-driver-build\src\MongoDB.Driver\Linq\Translators\PredicateTranslator.cs:line 1410

This is all generated from the OData call (using linqpad):
Collection.Where(a => a.Id == 20150525 && a.ItemId.StartsWith("Environment"))

Any thoughts on how I should be doing this differently, or where the potential issue might be occurring?

Comment by Craig Wilson [ 07/May/15 ]

Hi Calvin,

Thanks for the report. We don't have IQueryable support in the new API, so I assume you are referring to the old API. If that is the case, then we won't be fixing this. However, the new API should support most OData conventions.

Craig

Generated at Wed Feb 07 21:39:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.