Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linq collection Contains to OData Filter 'property' ´in´ (list of values) #612

Open
houbi56 opened this issue Apr 25, 2019 · 3 comments
Open
Assignees

Comments

@houbi56
Copy link

houbi56 commented Apr 25, 2019

In the OData 4 standard there's an expression:
http://host/service/Products?$filter=Name in ('Milk', 'Cheese')

(http://docs.oasis-open.org/odata/odata/v4.01/csprd02/part2-url-conventions/odata-v4.01-csprd02-part2-url-conventions.html#sec_LogicalOperatorExamples)

--
How do I write LINQ that gets interpreted to that?

var list = new List {"1" };
client.Filter(x => x.someprop == 2 && list.Contains(x.prop));

Throws exception:

Microsoft.OData.ODataException: The type 'System.Collections.Generic.List1[System.String]' is not supported when converting to a URI literal. at Microsoft.OData.Evaluation.LiteralFormatter.FormatRawLiteral(Object value) at Microsoft.OData.Evaluation.LiteralFormatter.FormatAndEscapeLiteral(Object value) at Microsoft.OData.Evaluation.LiteralFormatter.DefaultLiteralFormatter.FormatLiteralWithTypePrefix(Object value) at Microsoft.OData.Evaluation.LiteralFormatter.DefaultLiteralFormatter.Format(Object value) at Simple.OData.Client.V4.Adapter.CommandFormatter.ConvertValueToUriLiteral(Object value, Boolean escapeDataString) at Simple.OData.Client.ODataExpression.Format(ExpressionContext context) at System.Linq.Enumerable.SelectListIterator2.MoveNext()
at System.String.JoinCore[T](Char* separator, Int32 separatorLength, IEnumerable1 values) at Simple.OData.Client.ODataExpression.FormatMappedFunction(ExpressionContext context, FunctionMapping mapping) at Simple.OData.Client.ODataExpression.FormatFunction(ExpressionContext context) at Simple.OData.Client.ODataExpression.Format(ExpressionContext context) at Simple.OData.Client.ODataExpression.Format(ExpressionContext context) at Simple.OData.Client.FluentCommand.Resolve() at Simple.OData.Client.FluentCommand.GetCommandTextAsync(CancellationToken cancellationToken) at Simple.OData.Client.ODataClient.FindEntriesAsync(FluentCommand command, Boolean scalarResult, ODataFeedAnnotations annotations, CancellationToken cancellationToken) at Simple.OData.Client.FluentClientBase2.FilterAndTypeColumnsAsync(Task1 entries, IList1 selectedColumns, String dynamicPropertiesContainerName)

@object object self-assigned this Apr 25, 2019
@object
Copy link
Member

object commented Apr 25, 2019

This is not yet supported by the library: Contains is only implemented for string operations. I am adding this feature to a wish list, will checkout how hard it is to implement.

@houbi56
Copy link
Author

houbi56 commented May 6, 2019

Did a quick and dirty draft implementation. Would you mind giving some comments on how you would like this functionality to be implemented?

houbi56@4ed219e

@msavaria
Copy link

@object Any development on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants