0
votes

OData - Query requests with two contains doent work

Please find the below query that we are sending from the from fe (react ) when we are trying to search with two text boxes .It doesnt return any result. However an oData query with two dropdowns / onetextbox and one dropdown works/single textbox works
we suspect that this is due to the fact that two eq /one contains works fine however two contaisn doesnt work https://locallhost/api/odata/pageoverview?$count=true& $filter=(contains(OccasionName,%27ifrs_17%27)%20and%20contains(Name2,%27Test%27))&$

Update There is a continous URL $ which is this

https://localhost:3333/OverviewItem?$count=true&$filter=(contains(name1,'seek') and contains(name2,'aron') &$orderby=name1 desc,name2 desc &$skip=0&$top=10

On further Research we also find that in Controller which receives value the filter value on queryoptions is mixed up like name1 value is 'aron'instead of 'seek' .Is there any way we can correct this

public IQueryable Get(ODataQueryOptions odata) { //// }

2

2 Answers

0
votes

The url format may be not correct. I test the two contains and other conditions on local machine.

https://localhost:[]/odata/OverviewItem?$count=true&$filter=(contains(Name1,'param1') and contains(Name2,'param2'))&$orderby=Name desc,id desc&$top=3&$skip=2

I put orderby outside the filter, and the configuration as:

app.UseMvc(routeBuilder =>
        {
            routeBuilder.Select().Filter().OrderBy().Count().SkipToken().MaxTop(10);
            routeBuilder.MapODataServiceRoute("odata", "odata", GetEdmModel());
            
        });

$top value should be smaller than MaxTop.

0
votes

Looks like you are missing a closing parentheses after 'contains(name2,'aron')'

https://localhost:3333/OverviewItem?$count=true&$filter=(contains(name1,'seek') and contains(name2,'aron') &$orderby=name1 desc,name2 desc &$skip=0&$top=10

should be

https://localhost:3333/OverviewItem?$count=true&$filter=(contains(name1,'seek') and contains(name2,'aron'))&$orderby=name1 desc,name2 desc &$skip=0&$top=10