OData - Query requests with two contains doent work

vidya KR 1 Reputation point
2021-01-06T10:26:34.817+00:00

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 contains doesnt work

https://locallhost/api/odata/pageoverview?$count=true& $filter=(contains(OccasionName,%27ifrs_17%27)%20and%20contains(Name2,%27Test%27))&$

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,553 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rena Ni - MSFT 2,066 Reputation points
    2021-01-07T09:32:38.83+00:00

    Hi @vidya KR ,

    My whole working demo:

    Model:

    public class WeatherForecast  
    {  
        public Guid Id { get; set; }  
      
        public string TemperatureC { get; set; }  
      
        public string Summary { get; set; }  
    }  
    

    Startup.cs:

     public void ConfigureServices(IServiceCollection services)  
      {  
            services.AddControllers();  
            services.AddOData();  
      }  
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)  
      {  
            app.UseHttpsRedirection();  
      
            app.UseRouting();  
      
            app.UseAuthentication();  
            app.UseAuthorization();  
       
            app.UseEndpoints(endpoints =>  
            {  
                endpoints.MapControllers();  
                endpoints.Select().Filter().OrderBy().Count().MaxTop(null);  
                endpoints.MapODataRoute("api", "api", GetEdmModel());  
            });  
      }  
      private IEdmModel GetEdmModel()  
      {  
            var odataBuilder = new ODataConventionModelBuilder();  
            odataBuilder.EntitySet<WeatherForecast>("WeatherForecast");  
            return odataBuilder.GetEdmModel();  
      }  
    

    Controller:

    //[ApiController]  
    //[Route("[controller]")]  
    public class WeatherForecastController : ControllerBase  
    {  
        [EnableQuery()]  
        [HttpGet]  
        public List<WeatherForecast> Get()  
        {  
            var model = new List<WeatherForecast>()  
            {  
                new WeatherForecast(){Summary="a",TemperatureC="cvv"},  
                new WeatherForecast(){Summary="ass",TemperatureC="xc"},  
                new WeatherForecast(){Summary="dd",TemperatureC="sd"}  
            };  
            return model;  
        }  
    }  
    

    Request url: api/weatherforecast?$count=true& $filter=(contains(Summary,'a') and contains(TemperatureC,'c'))&$orderby=Summary desc,TemperatureC desc &$skip=0&$top=10

    Result:

    54712-capture.png


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    Rena


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.