Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I test for an empty Breeze predicate?
    primarykey
    data
    text
    <p>I'm using Breeze to filter data requested on the client. My code looks a little like this:</p> <p><strong>Client - Creating Filter Predicate</strong></p> <pre><code>var predicates = []; var criteriaPredicate = null; $.each(selectedFilterCriteria(), function (index, item) { criteriaPredicate = (index == 0) ? breeze.Predicate.create('criteriaId', breeze.FilterQueryOp.Equals, item) : criteriaPredicate.or('criteriaId', breeze.FilterQueryOp.Equals, item); if (breeze.Predicate.isPredicate(criteriaPredicate)) { predicates.push(criteriaPredicate); } // Repeat for X Filter Criteria var filter = breeze.Predicate.and(predicates); return context.getAll(filter, data); </code></pre> <p><strong>Client - Context Query</strong></p> <pre><code>function getAll(predicate, dataObservable) { var query = breeze.EntityQuery.from('Data'); if (breeze.Predicate.isPredicate(predicate)) { query = query.where(predicate); } return manager.executeQuery(query).then(success).fail(failure); } </code></pre> <p><strong>Issue</strong></p> <p>I'm having an issue with the request because, if there are no filters set, I apply an "empty" predicate (due to the <code>var filter = breeze.Predicate.and([])</code> line) resulting in a request like <code>http://mysite/api/app/Data?$filter=</code>. The request is an invalid OData query since the value of the $filter argument cannot be empty.</p> <p>Is there a good way for me to check for an empty predicate? I know I can refactor my client code to not use a predicate unless there is at least one filterable item, but I thought I would check first to see if I overlooked some property or method on the Breeze Predicate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload