Bill
Bill

Reputation: 2382

OData - Breeze - Custom Query

I am using Breeze for a SPA application. The backend data is coming from accessing an API (not EF).

I exposed "Tasks" as a Queryable collection.

In some cases, I want to request a single Task by Id. The OData filter will be sent to the server, but then Breeze, will have to query all Tasks in the database and then apply filter.

Is there a way to intercept the OData filters, and go get myself the single record requested?

Thanks

Upvotes: 1

Views: 229

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

You can use the Breeze EntityQuery.withParameters method.

// Client
var query = new EntityQuery("GetTaskById").withParameters( { "taskId": 126 });
myEntityManager.executeQuery(query).then(...)

// Server
[HttpGet]
public Task GetTaskById(int taskId) {
   // your task code.
}

Note that you can return either a scalar result or an IQueryable which means that you can also mix and match EntityQuery.where clauses with EntityQuery.withParameter clauses.

Hope this helps.

Upvotes: 1

Related Questions