Andrew Davis Andrew Davis - 1 year ago 67
Javascript Question

Using Breezejs generate query string

I have a custom Odata endpoint which gets it filter via a post from the body and not the query string. At the moment all of the queries are hand coded and then fed in to the post.
I was wondering if anyone knows if I can use Breezejs just to create the query I need.


Answer Source

According to the "OData AJAX" section in Controlling AJAX you'll need to make changes to your copy of data.js so that POST is used instead of GET.

If you don't care to have breeze load the data and just want to use the EntityQuery syntax to build queries you could try getting an instance of the breeze odata uriBuilder and call the buildUri method to convert the EntityQuery to an odata uri. Assuming that works, it would be a matter of grabbing the querystring component of the uri to use in your POST body.

var interfaceRegistry = breeze.config.interfaceRegistry,
    uriBuilderInterface = interfaceRegistry.uriBuilder,
    uriBuilderCtor = uriBuilderInterface.getImpl('odata').ctor,
    uriBuilder = new uriBuilderCtor(),
    uri = uriBuilder.buildUri(entityQuery, metadataStore);

There might be a better/simpler way of doing this... maybe by grabbing the uriBuilder from a breeze odata dataService instance. I don't think this is part of breeze's supported/documented public api but it sounds like it would make a nice feature suggestion to post on the user voice site.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download