Please have a look at the below for the details ->
How to Develop Query Options for an OData Service Using Code-Based Implementation
Please have a look at the below for the details ->
How to Develop Query Options for an OData Service Using Code-Based Implementation