AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

Handle of max top in query #177

Closed andreamorello93 closed 1 year ago

andreamorello93 commented 1 year ago

i'm trying to figure out how to handle MaxTop in sql query that is handled in EnableQuery Attribute in standard configuration:

my controller:

BaseODataDTOController.cs

Generated SQL query for request: https://localhost:44393/odata/product

SELECT [p].[ProductID] AS [ProductId] FROM [Production].[Product] AS [p]

As you can se there's no top in sql statement. how can i fix this?

leoerlandsson commented 1 year ago

Hi,

Setting a PageSize before running the query will generate a TOP statement:

querySettings.ODataSettings.PageSize

public async Task<IEnumerable> Get([SwaggerHide] ODataQueryOptions options) => (await _repository.Queryable().GetQueryAsync(_mapper, options, querySettings));

Br, Leo

andreamorello93 commented 1 year ago

Thank you Leo!