Question

How to write complex queryies with BreezeJS + OData or WebAPI? What I want to be able is something like this in JayData, using Northwind as reference db? My problem is I don't know how to express queries that has both side referencing the database (not a field compared to a constant) and also that has complex logical trees ( a || (b && c))?

context.Products.filter(function(product) {
   return (product.Unit_Price < product.Category.BudgetPriceLimit) || 
   (product.Category.IsOnSale && product.Supplier.IsFavored)
}).toArray(...)

My other question is about TypeScript + querying. How one can use Arrow functions for queries with BreezeJS? So instead of the expression builders is there a way to say:

query(Product => Product.Unit_Price < Product.Category.BudgetPriceLimit)

Thank you for your help, sorry if these are obvious questions.

Was it helpful?

Solution

This post has been edited to correct a mistake on my part as well as new capabilities that have been added to breeze as of v 0. 77.1.

Good questions!

Breeze now supports cross property query expressions (as of v 0.77.1), such as the following:

var shippedLateQuery = EntityQuery.from("Orders")
                                  .where("requiredDate",">","shippedDate");

The third parameter ("shippedDate" above) will treated as either a property expression or a literal depending on context. In general, if the value can be interpreted as a property expression it will be, otherwise it will be treated as a literal. In most cases this works well, but you can also force the interpretation. Please see the API Docs for more details.

Composing complex queries, i.e. ( a || (b && c)), with breeze is accomplished via Predicates. There are some good examples here:

Query Examples - see the Compound Conditions with Predicates topics

Also, the first breeze tutorial here: Tutorial also lets you try out the capabilities (see step 5).

We are actively following Typescript and have plans to fully enable it, but we are still early in the process.

UPDATE: As of v 0.84.4, Breeze provides full TypeScript support.

OTHER TIPS

Until Breeze supports field-to-field comparisons, you might consider writing custom query methods on the server-side controller that construct the LINQ queries that can do your field-to-field comparisons. To give your client more flexibility, it can pass parameters that your controller method interprets to influence the query construction; use the withParameters clause. You can combine OData query clauses and the withParameters clause.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top