Search code examples
entity-frameworkasp.net-web-apiodatabreeze

BreezeJS does not perform filtering in database?


I am using the following query on the client:

var query = breeze.EntityQuery.from("AllCustomers").where("CustomerId,"==",criteriaValue);
return this.manager.executeQuery(query)

which results in the following URL: /breeze/myAPI/AllCustomers?$filter=CustomerId%20eq%2012

I have noticed that the filtering is not performed in the database (there is no WHERE statemenet in dthe SQL executed by the database). I suspect, that the reason for this is Breeze.WebApi.QueryHelper.WrapResult, which calls Enumerable.ToList. The later converts IQueriable to list which forces execution of the query before if is filtered by default Microsoft OData implementation:

// if a select or expand was encountered we need to
// execute the DbQueries here, so that any exceptions thrown can be properly returned.
// if we wait to have the query executed within the serializer, some exceptions will not
// serialize properly.
queryResult = Enumerable.ToList((dynamic)queryResult);
queryResult = PostExecuteQuery((IEnumerable)queryResult);

Is this a bug in Breeze or am I doing something wrong?

I am using Oracle ODP.NET provider for entity framework.

UPDATE: I am using WebAPI and the controller method quite simple:

[BreezeController]
public class MyController : ApiController
{

[HttpGet]
public IQueryable<Customer> AllCustomers()
{            
  return  _contextProvider.Context.Customers;
}

Solution

  • Ok, this was a bug and has been fixed. The fix will be available in our next full tested release (v 1.4.3 ) or you can get our current dev version now from the Breeze Git repository.

    Note that this issue only happens with a badly constructed filter against a query that involves a "named query" on the server and where the client DOES NOT have an entityType/resource name mapping for the queried resource. In the condition where the Breeze client DOES have an entityType/resourceName mapping any invalid filter will throw a client side error before even going to the server.

    and... Thanks for reporting it. :)