Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OData Exception The limit of '0' for Top query has been exceeded

I am using OData Web API for Version 4, when I try to query OData web Api using $top parameter, it return me following exception message.

The query specified in the URI is not valid. The limit of '0' for Top query has been exceeded. The value from the incoming request is '10'

I am using Apache Ignite dotNet LINQ as data source instead of Entity Framework, my OData controller action method is as follows:

[EnableQuery]
public IQueryable<Productioncurvepnl> GetProductioncurvepnl()
{
    Console.WriteLine("Starting query to ignite");
    var q = AIgniteClient.IgniteClient.Instance.ProductionCurvePnLCache.AsCacheQueryable().Select(c => c.Value);
    return q;
}
like image 710
Abdul Qadir Memon Avatar asked Sep 21 '16 17:09

Abdul Qadir Memon


3 Answers

Since Web API OData V6.0.0 you need to enable query options to have this work. This can be done globally in the WebApiConfig.Register(HttpConfiguration config)

config.Select().Expand().Filter().OrderBy().MaxTop(null).Count();

or directly on your models, for fine grained configuration:

[Page(MaxTop = 100)]
public class Products

If you're using Model Bound Fluent APIs and cannot add attributes, you'll need to append the query options. For example .Page(50, 50):

 builder.EntitySet<AccountRecordDto>("Accounts").EntityType.Expand(1, 
 "Transactions").Count().Page(50, 50);

More details can be found in the documentation

like image 93
ogrim Avatar answered Nov 15 '22 11:11

ogrim


Adding below in Startup.cs works for me

config.Select().Expand().Filter().OrderBy().MaxTop(null).Count();
like image 24
jt03 Avatar answered Nov 15 '22 13:11

jt03


Based on the returned error message the problem most likely is that the MaxTop is not defined. You can do that using the EnableQueryAttribute on your method like so (change the value as you see fit), I used a value of 100.

[EnableQuery(MaxTop = 100)]
public IQueryable<Productioncurvepnl> GetProductioncurvepnl()
{
    Console.WriteLine("Starting query to ignite");
    var q = AIgniteClient.IgniteClient.Instance.ProductionCurvePnLCache.AsCacheQueryable().Select(c => c.Value);
    return q;
}

See EnableQueryAttribute for more details.

like image 28
Igor Avatar answered Nov 15 '22 11:11

Igor