You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please forgive me if the question is too simple, as I'm trying to understand the functionalities.
I have a scenario where I need to implement specific query parameters (mostly skiptoken and filter) and I was looking into using this library. However, the project is big enough that conforming to the EDM model/odatacontrollers is quite a bit of work. I was wondering if there is a simple way to reuse the handlers without needing to register/confirm to EDM models?
for example, for skip token, I have a custom logic for producing the skip token and fetching the next page from it, but if I were to override DefaultTokenHandler, that would require me to create an ODataSerializerContext and have it register with an edm routeprefix in the hostbuilder. ODataQueryOptions seems to correctly parse the queries so I think it would be nice if:
I can configure services directly in the options (without needing to pass a routePrefix, modelBuilder)
ApplyTo for SkipTokenHandler to allow me to pass a custom page fetching logic while reusing the uri building mechanisms in place (top/pagesize handling, conflict with other query parameters, etc)
GenerateNextPageLink to don't depend on ODataSerializerContext
Does this makes sense? please let me know if there is a better way
IMPORTANT: Please note that the response you get back is not an OData response
@JoseLimaIVD I believe you can create a minimal EDM model that only contains model definition of a specific entity type. ODataQueryOptions can parse query parameters like $filter, $orderby, $top, and $skiptoken without requiring a full EDM model registration. However, some advanced features like SkipTokenHandler and GenerateNextPageLink are tightly coupled with the OData pipeline and ODataSerializerContext.
Here’s a simple example of how to parse $filter and $top using ODataQueryOptions with a minimal EDM model, without needing to fully adopt OData controllers or route prefixes.
[Route("api/[controller]")][ApiController]publicclassProductsController:ControllerBase{[HttpGet]publicIActionResultGetFilteredProducts(){varedmModel=GetEdmModel();varcontext=newODataQueryContext(edmModel,typeof(Product),newODataPath());varqueryOptions=newODataQueryOptions<Product>(context,Request);IQueryable<Product>?products=GetProducts();// Apply $filter and $topif(queryOptions.Filter!=null){products=queryOptions.Filter.ApplyTo(products,newODataQuerySettings())asIQueryable<Product>;}// Apply $top if specifiedif(queryOptions.Top!=null){products=queryOptions.Top.ApplyTo(products,newODataQuerySettings());}returnOk(products);}// This model is just enough to allow parsing of OData queries for the Product type.privatestaticIEdmModelGetEdmModel(){varbuilder=newODataConventionModelBuilder();builder.EntitySet<Product>("Products");returnbuilder.GetEdmModel();}// Simulate a data sourceprivatestaticIQueryable<Product>GetProducts(){returnnewList<Product>{...}.AsQueryable();}}
Sample Requests
GET /api/products?$filter=Price gt 500&$top=2
GET /api/products?$filter=Category eq 'Category3'&$top=2
Activity
WanjohiSammy commentedon Jun 24, 2025
IMPORTANT: Please note that the response you get back is not an OData response
@JoseLimaIVD I believe you can create a minimal EDM model that only contains model definition of a specific entity type.
ODataQueryOptionscan parse query parameters like$filter,$orderby,$top, and$skiptokenwithout requiring a full EDM model registration. However, some advanced features likeSkipTokenHandlerandGenerateNextPageLinkare tightly coupled with the OData pipeline and ODataSerializerContext.Here’s a simple example of how to parse
$filterand$topusingODataQueryOptionswith a minimal EDM model, without needing to fully adopt OData controllers or route prefixes.Sample Requests
Non-OData response:
[ { "id": 3, "name": "Product3", "price": 30, "category": "Category3" }, { "id": 6, "name": "Product6", "price": 60, "category": "Category3" } ]