OData (create custom) query option

Viewed 4077

i need to create a custom query option and to be honest i have no idea where to start from. i don't know how they are created or what class handles them. On my project i have used markdown but i also need to enable ( in which case the text marked will be markdown ) or disable ( in this case i will have plain text ).

at this point my solution was to send a parameter to a function and tell it when to enable / disable

EX:

.../.../Namespace.MyFunction(markdown=1)

but i'm looking for a way to obtain this

.../.../...?$markdown=true

something like count query option.

Thank you

2 Answers

Since you're using ASP.NET, you can also just use regular parameter binding.

For example, an ODataController action method with the following prototype:

[EnableQuery]
public IQueryable<MyEntity> Get(string testParam = "")

will service a request at the following URL:

http://your.machine/api/odata/myentity?$count=true&$top=10&$skip=0&testParam=true

The OData parameters $count, $top, and $skip will all be honored, and your custom testParam will have the string "true" assigned within the Get method.

Related