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:
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