.Contains() should be supported
Any .Contains() in a .Where() clause, could easily be decomposed by the OData client's IQueryable expression tree visitor into a list of "ORed" conditionals, even if .Contains() is not strictly supported by OData directly with an equivalent URI.
This is at least, or especially, true if the list is a simple value type list rather than a list of complex.
Assemblies affected
Microsoft.OData.Client v4.0.30319 Microsoft.OData.Core v4.0.30319 Microsoft.OData.Edm v4.0.30319
Reproduce steps
Execute the following or equivalent against any OData endpoint using the standard T4 generated client.
var values = new string[] { "val1", "val2" }; odataClient.MyCollection.Where(x => list.Contains(x.prop))
Expected result
The list.Contains() clause should be converted into a series of "ORed" conditionals in the generated URI which is fully supported by OData and allows easier use of the client.
Actual result
Depending on how you execute .Contains(), either NotSupportedException or a more confusing variant (see issues/608).
I just ran into this, trying to filter an entity set by a collection of in-memory values.
Per the example:
var values = new string[] { "val1", "val2" };
odataClient.MyCollection.Where(x => values.Contains(x.prop))
My expectation was that this gets translated to in.
GET /odata/MyCollection?$filter=prop in ('val1', 'val2')
Is is possible to add this behavior? Is there a workaround?
There are two Contains methods that result in different behavior:
ICollection<T>.Contains()which is implemented byList<T>Enumerable.Contains<TSource>(this IEnumerable<TSource> source, TSource value)for arrays and other enumerables
The latter was easy to implement but ICollection
Fixed by https://github.com/OData/odata.net/pull/1868