-
Notifications
You must be signed in to change notification settings - Fork 31
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
Dynamics Or Filter support #120
Comments
While not explicitly supported this is still doable by dynamically creating the expression. Here is an example in the form of a test using the TestClasses in this library var validValues = new List<string>
{
"44",
"45"
};
var entityType = typeof(ODataTypeEntity);
var filterParameter = Expression.Parameter(entityType, "s");
var expr = validValues
.Select(v => Expression.Equal(
Expression.Property(filterParameter, nameof(ODataTypeEntity.TypeCode)),
Expression.Constant(v)))
.Aggregate(Expression.OrElse);
var filter = Expression.Lambda<Func<ODataTypeEntity, bool>>(expr, filterParameter);
var uri = _odataQueryBuilderDefault
.For<ODataTypeEntity>(s => s.ODataType)
.ByList()
.Filter(filter)
.ToUri();
uri.Should().Be("http://mock/odata/ODataType?$filter=TypeCode eq '44' or TypeCode eq '45'"); There are also other ways to construct the expression, for example by having a list of expressions and merging them. You might want to take a look at that to see if there is another way you prefer. |
Thank you very much for the suggestion. That's exactly how did I solve it for now:
But I'd like to have such code in Framework itself and also if I want a more complex scenario like that
In that case such expression will become more complex and easier to use by |
Agreed, it can get confusing quickly. |
Hi, my OData service doesn't support In statement and I need to make code like that:
but this code will generate Url like tha
baseUrl/MyEntity?$filter=Email eq '[email protected]' and Email eq '[email protected]'
How can I get the filter dynamically with OR statement instead of AND? I would like to have code like that
that will generate this url
baseUrl/MyEntity?$filter=Email eq '[email protected]' or Email eq '[email protected]'
Is it possible to add such support? Thanks
The text was updated successfully, but these errors were encountered: