0

I'm using OData with Entity Framework to select some records from a database. The records each have a path to a file with text content. In a single service call I'd like to be able to filter the DB records as well as filter the resulting objects based on the content of the files that the records point to. Because I can't mix LINQ to EF with LINQ to Objects, I believe the easiest way to accomplish this is to add an additional query parameter to the standard OData parameters that defines how to filter for file content after the standard odata filters have been applied.

Is looks like the entity query's "withParameters" method is the way to add a non-standard parameter but it doesn't seem to work with version 1.4.9 of breeze.

Am I doing something wrong or is there any intention to make this method work for the OData service provider?

2 Answers 2

0

As a workaround to this shortcoming, I've found that you can declare your entity to query with the parameters as part of the entity name, like so:

var entityId = 4;
var answerId = 6;
var entityToQuery = "MyEntity(EntityId=" + entityId + ",answerId=" + answerId + ")";

Then, build your breeze query:

var query = breeze.EntityQuery.from(entityToQuery);

This would map to an OData endpoint such as:

public IQueryable<MyEntity> GetMyEntity([FromODataUri] int entityId, [FromODataUri] int answerId) { }

1
  • Where do you get FromODataUri? I'm getting error saying invalid argument :-(
    – Sebastian
    May 5, 2015 at 10:51
-2

No, you need to use the WebApi adapter. This is not a breeze shortcoming, it's a OData shortcoming because OData doesn't support this syntax.

However, the WebApi adapter does do everything you want and this is the Breeze default. Please see the docs for more information.

5
  • This answer suggested that the feature was possibly getting added. Is that no longer the case? If so, is there a way to have breeze construct an odata query to a string so that I can use it to construct a regular web api call?
    – BahKoo
    Mar 4, 2014 at 1:50
  • This is what breeze does out of the box. It uses OData syntax to talk to WebApi, and adds additional parameters to support the withParameters call. Mar 4, 2014 at 5:04
  • Thanks! I believe I understand now.
    – BahKoo
    Mar 4, 2014 at 5:59
  • Actually it is a Breeze shortcoming, you should be able to use .withParameters when talking to an OData endpoint, and it will be addressed. If you can achieve your objectives with the Web API (not Web API OData), by all means do so.
    – Ward
    Mar 5, 2014 at 1:47
  • Odata v2 does support custom Parameters: odata.org/documentation/odata-version-2-0/uri-conventions
    – Sebastian
    May 5, 2015 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.