Search code examples
breeze

Get BreezeJS ODATA query parameters on server side to update entity during query


How do I get handle of the OData query parameters in a Brezze WebApi controller?

I have a endpoint where only a single entity will be queried at a time. The controller just calls a repository that returns a context.Set().AsQueryable();

I want to be able to get the entity ID out of the parameters and update(plain EF) a count property on it before querying it for the response.

Thanks


Solution

  • I found what I needed.

    By adding a ODataQueryOptions<T> odataQueryOptions argument to the endpoint I was able to access the OData query parameters and get the ID I needed by getting this property:

    var where = odataQueryOptions.RawValues.Filter;
    

    Filter value in my case looks like this: Id eq 'dd3d6cb2-bc7a-467e-9730-c43c333b6fda'

    Edit: If you use .withParameters() on your breeze query object, you can pass additional parameters to your end-point without bothering to deal with OData.