Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Counts in Breeze.js

I have a complex query that returns item counts. If I run a query on the client, will it always return the objects, or is there a way to just return the item counts without sending the object array in the payload? I tried doing something like

var query = breeze.EntityQuery.from('Items').inlineCount(true);

but that still pulls all the records down. Any solutions?

like image 565
Ali B Avatar asked May 06 '13 01:05

Ali B


People also ask

What are optional Breeze server components?

Optional breeze server components make it easier to build services that support breeze client applications. Learn more about these technology opportunities:

What is the breeze repository?

This repository holds the Breeze assets for HTML/JS client development. For technical questions, please go to StackOverflow with the tag "breeze". StackOverflow is a fantastic site where tons of developers help each other with their technical questions. We monitor this tag on the StackOverflow website and do our best to answer your questions.

How to count the number of times console is called?

More examples below. The count () method counts the number of times console.count () is called. The count () method this number to the console. You can add a label that will be included in the console view. As a default value the label "Default" is used. See more examples in the bottom of this page. Optional. Default label is "Default".


Video Answer


2 Answers

I don't know if this exactly answers your question, but you would need to query the records in order to know how many there are (to my knowledge, there may be a more efficient way to tie Breeze directly into a SQL command that is way over my head) so you could do something like -

var query = breeze.EntityQuery.from('Items')
    .take(0)
    .inlineCount(true);

Edited the answer - this would return no objects and simply get the count.

like image 104
PW Kad Avatar answered Oct 20 '22 22:10

PW Kad


The inlineCount answer already provided is absolutely correct.

Another alternative is to calculate the counts on the server and just send down the "summary". For example this server side controller method will return an array of two element objects to the client:

  [HttpGet]
  public Object CustomerCountsByCountry() {
    return ContextProvider.Context.Customers.GroupBy(c => c.Country).Select(g => new {g.Key, Count = g.Count()});
  }

This would be called via

  EntityQuery.from("CustomerCountsByCountry")
     .using(myEntityManager).execute()
     .then(function(data) {

     var results = data.results;
     results.forEach(function(r) {
       var country = r.Key;
       var count = r.Count
     });

  });
like image 30
Jay Traband Avatar answered Oct 20 '22 22:10

Jay Traband